Skip to content

NiBlockRefArray: fix Resize loop and keep arraySize consistent#18

Merged
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/niblockrefarray-resize-and-sync
Apr 25, 2026
Merged

NiBlockRefArray: fix Resize loop and keep arraySize consistent#18
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/niblockrefarray-resize-and-sync

Conversation

@MANOLOV02
Copy link
Copy Markdown
Contributor

Three related issues in NiBlockRefArray:

  1. Resize grow loop starts at 0. When growing from cur > 0 to size, the loop for (int i = 0; i < size; i++) Add(...) appends size extra entries instead of size - cur, leaving the list at cur + size. Fix: start the loop at cur.
  2. AddBlockRef doesn't bump _listSizeStream. The mirror that gets serialized stays stale until an explicit Sync(). Matches nifly/include/BasicTypes.hpp:863-872 where C++ does arraySize++ atomically inside AddBlockRef.
  3. RemoveBlockRef has the symmetric bug. Matches nifly/include/BasicTypes.hpp:886-890 (arraySize--).

Maps to issue #15 items D10 and D11.

MANOLOV02 and others added 2 commits April 25, 2026 17:46
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--`).
@ousnius ousnius merged commit d055d53 into ousnius:main Apr 25, 2026
1 check passed
@MANOLOV02 MANOLOV02 deleted the fix/niblockrefarray-resize-and-sync 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