Skip to content

dwg_next_handle: scan all objects for the max, as the comment promises - #1382

Open
tuxiasumari wants to merge 1 commit into
LibreDWG:masterfrom
tuxiasumari:fix-next-handle-max
Open

dwg_next_handle: scan all objects for the max, as the comment promises#1382
tuxiasumari wants to merge 1 commit into
LibreDWG:masterfrom
tuxiasumari:fix-next-handle-max

Conversation

@tuxiasumari

Copy link
Copy Markdown
Contributor

Symptom

Importing an R12 DXF (its own handles present, $HANDLING 1):

ERROR: Duplicate handle 1F for object 43 already points to object 0
ERROR: Duplicate handle B for object 52 already points to object 29

and the emitted DWG's object map points two objects at one handle, so readers resolve the wrong objects.

Root cause

dwg_next_handle's comment says "check the objects for the highest handle" — but the loop takes the handle of the last object with a nonzero handle and stops:

for (j = dwg->num_objects; !seed && j > 0; j--)
  { ... seed = o->handle.value; break; }

That is only the maximum when objects are appended in increasing handle order. During a DXF import they are not: pre-created table objects carry high handles (0x1F, ...) before the file's own low handles arrive, so fresh objects get handles already in use.

Fix

Scan all objects for the true maximum, matching the comment and the refs pass below it (which already scans everything).

make check green; 1657-file real-DWG corpus unchanged.

The loop took the handle of the LAST object with a nonzero handle and
stopped. That is only the maximum when objects happen to be appended in
increasing handle order; during a DXF import they are not (pre-created
table objects carry high handles before the file's own low handles
arrive), so freshly created objects got handles already in use:

  ERROR: Duplicate handle 1F for object 43 already points to object 0

and the emitted DWG's object map pointed two objects at one handle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla_needed Waiting for the Copyright assignment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants