Roadmap 0.11, Fixes
FX.447 CadCraft DWG: Plans.dwg lost 15 block references (INSERTs) when saved as DWG and opened again
WHAT WAS WRONG: opening testfiles Plans.dwg (16,631 objects) and saving it as DWG (new worker save and the old on-page save alike) gave 16,616 on reopening. The 15 lost objects were all INSERTs in model space on layer 0: 3 of block PKT and 12 of block PLAVA. The writer left them out with the note "15 x INSERT of a block the drawing does not define", but the cause was the reader: the program that wrote Plans.dwg puts a plot style handle (the Normal placeholder, ACDBPLACEHOLDER 8) after the layer handle of its entities while the entity's plot style flags say ByLayer (0). Reading by the flags alone, each later handle was taken one place early: those INSERTs got the placeholder as their block (shown as block "8"), and 2 MTEXTs got it as their text style. The ODA File Converter reads the same INSERTs as PKT / PLAVA. 169,374 entities in that file carry the extra handle; for LINE, 3DFACE, LWPOLYLINE and the like it changed nothing visible.
CHANGED: lib/dwg/objects-read.js reads an entity again with the plot style handle when a whole handle is left over in its handle stream after decoding (AutoCAD's stream holds exactly the handles the flags name, padded to under a byte), and keeps that reading only when it uses the stream up exactly without an error; lib/dwg/read.js then keeps it only when the handle names an ACDBPLACEHOLDER, else the first reading stands. Entities whose decoder reads no handles of their own only have their common handles read again (no second decode). Copies synced to every app's dwg/ (writer-sync, --check: all identical). The writer is unchanged.
TESTS: Plans.dwg round trip in Node 16,631 -> 16,631 with the same count per kind and per kind+layer+block+style (anonymous *D/*U names aside); /lab/cadcraft page: open Plans.dwg, SAVEAS DWG 2018, reopen in a fresh page: 16,631 -> 16,631, no kind differs, the 15 PKT/PLAVA INSERTs there both times, no page errors. New fixture tools/dwg-test/plotstyle-handle.mjs (our writer writes a small drawing with the extra handle added, AutoCAD 2004/2010/2018: INSERTs keep their block, MTEXT its style, the round trip keeps both INSERTs, a non-placeholder extra handle is not taken; 30/0, and 12 of its checks fail with the old reader), in tools/dwg-test/test.mjs section plotstyle (138/0). identity corpus (tools/dwg-perf/identity.mjs against the old reader): 564 writes and 94 reads of 95 files, 0 differ. bin/test-cadcraft.mjs 2992/0, bin/test-cadcraft-3d.mjs 149/0. Reading Plans.dwg takes about 0.1 to 0.3 s longer (about 1.1-1.5 s -> 1.3-1.8 s on the VPS, under load).
UNTESTED: other drawings from the program that wrote Plans.dwg; entity types whose decoders do not read all their handles if such a file also carries the extra handle (they keep the old reading unless the second reading fits exactly and names a placeholder). In /lab (a Discord member) only, not released.
Community comments
No comments yet
Add detail as we go: how you would use it, files or steps that show the problem, what other programs do. The team reads every comment.
Sign in or create a free account to add a comment.