NiBlockRefArray: fix Resize loop and keep arraySize consistent#18
Merged
ousnius merged 2 commits intoousnius:mainfrom Apr 25, 2026
Merged
Conversation
Three related bookkeeping fixes in NiBlockRefArray matching the C++ nifly reference implementation in BasicTypes.hpp: 1. Resize: the fill loop was `for (i = 0; i < size; i++) Add(...)` which, on a non-empty array, appended `size` entries and ended at `cur + size` instead of the requested `size`. Fresh loads were fine (cur = 0) but any runtime grow broke. Start from `cur` to only fill the new slots — matches `refs.resize(arraySize)` in BasicTypes.hpp:863. 2. AddBlockRef: did not update `_listSizeStream`, leaving the mirror count stale until the next Sync(). Matches BasicTypes.hpp:869-872 where AddBlockRef bumps `arraySize++` alongside the push_back. 3. RemoveBlockRef: same issue; now decrements the mirror together with the list RemoveAt. Matches BasicTypes.hpp:886-890 (`arraySize--`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three related issues in
NiBlockRefArray:Resizegrow loop starts at 0. When growing fromcur > 0tosize, the loopfor (int i = 0; i < size; i++) Add(...)appendssizeextra entries instead ofsize - cur, leaving the list atcur + size. Fix: start the loop atcur.AddBlockRefdoesn't bump_listSizeStream. The mirror that gets serialized stays stale until an explicitSync(). Matchesnifly/include/BasicTypes.hpp:863-872where C++ doesarraySize++atomically insideAddBlockRef.RemoveBlockRefhas the symmetric bug. Matchesnifly/include/BasicTypes.hpp:886-890(arraySize--).Maps to issue #15 items D10 and D11.