Skip to content

OptimizeFor toLE: report against bsOptShape after ReplaceBlock#24

Merged
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/optimizefor-tole-orphan-refs
Apr 25, 2026
Merged

OptimizeFor toLE: report against bsOptShape after ReplaceBlock#24
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/optimizefor-tole-orphan-refs

Conversation

@MANOLOV02
Copy link
Copy Markdown
Contributor

The toLE branch of OptimizeFor adds shape to several result.ShapesXxx lists, then calls ReplaceBlock(shape, bsOptShape) which orphans the original. Callers that read the result lists end up with references to the now-detached shape.

Five sites affected: ShapesVColorsRemoved, ShapesNormalsRemoved (which also had its own condition inverted — normals.Count == 0 should be > 0), ShapesTangentsAdded, ShapesParallaxRemoved, and the post-replace bookkeeping spot.

The toSSE branch already uses the "report after replace" ordering. This brings toLE in line.

C++ reference: nifly/NifFile.cpp:1823!normals.empty() for the normals condition.

Maps to issue #15 items A3 and A4.

MANOLOV02 and others added 2 commits April 25, 2026 17:46
The toLE branch fired result reports (ShapesNormalsRemoved,
ShapesParallaxRemoved, ShapesVertexColorsRemoved, ShapesTangentsAdded,
ShapesPartitionsTriangulated) referencing `shape` BEFORE calling
`ReplaceBlock(shape, bsOptShape)`. Once the replace runs, those
references point to an orphaned block that is no longer part of the
header.

Three issues addressed together:

1. Invert the normals-removed condition: was `if (normals.Count == 0)`
   which reports only when there are no normals (nothing to remove).
   Matches C++ NifFile.cpp:1823 `if (!normals->empty())`.

2. Capture each "did X" outcome in a local bool before the replace;
   fire the reports against `bsOptShape` afterwards.

3. The toSSE branch and the C++ implementation (NifFile.cpp:1773,
   1960) already use this "report after replace" ordering. Bring toLE
   in line.
@ousnius ousnius merged commit 539b04c into ousnius:main Apr 25, 2026
1 check passed
@MANOLOV02 MANOLOV02 deleted the fix/optimizefor-tole-orphan-refs branch April 25, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants