Skip to content

fix(savedata): preserve save size when recovering missing metadata - #2110

Closed
inmert wants to merge 4 commits into
boykopovar:mainfrom
inmert:fix/savedata-recovery-preserve-size
Closed

inmert wants to merge 4 commits into
boykopovar:mainfrom
inmert:fix/savedata-recovery-preserve-size

Conversation

@inmert

@inmert inmert commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Recovering missing save-data metadata can truncate an existing save when the caller requests a smaller memory size. With the recovery path in #1680, a 64-byte save becomes 32 bytes after a 32-byte setup request.

Keep the larger of the existing size and the requested size during recovery. Smaller and equal requests preserve the saved bytes; larger requests still grow the file and zero-fill the new space.

The regression test covers all three cases, checks the recovered metadata, and verifies that the data survives library termination and reinitialization.

Refs #1667. Depends on #1680. This branch includes that PR's original commits so the recovery path and this fix can be tested together. The follow-up fix and tests are in dfc477cc. Once #1680 merges, this branch can be rebased onto main to leave just the follow-up change for review.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON. Configured the full project and built the affected libraries and save-data test targets. Tests use synthetic save files; no game or console testing.

  • Before the fix, the new regression failed: Metadata recovery requested 32 bytes: expected 64 bytes, got 32.
  • After the fix, all 11 save-data CTest cases passed, with no skips. Total runtime was 6.03 seconds.
  • Repository conventions, test registration, and git diff --check passed.
ctest --test-dir build -R savedata --output-on-failure --timeout 30 --parallel 4

Checklist

emirplus and others added 4 commits October 8, 2026 19:18
Report SAVE_DATA_ERROR_INTERNAL when setupSaveDataMemory2 fails to persist initial SaveDataParam metadata, and restore previous state so retrying setup can initialize cleanly. Closes #1667.
…ck recovery

Write initial SaveDataParam metadata before replacing the memory blob so metadata failure cannot leave a prematurely grown blob. Handle blob write failure with metadata rollback, and allow retries to recover slots with missing metadata. Expand tests with nonzero data, blob failure, and fresh readback.
Keep the existing blob size when repairing missing metadata with a smaller memory request. Cover smaller, equal and larger requests, preserved bytes, zero-filled growth and library reinitialization.

Depends on upstream PR #1680. Reproduced the 64-to-32-byte truncation before the fix; all 11 save-data CTest cases pass with MinGW-w64 GCC 15.2.0 on Windows. AI-assisted.
@github-actions github-actions Bot added the prx label Oct 9, 2026
@Mouhand-Kaddo

Copy link
Copy Markdown
Contributor

Additional platform validation on standalone PR head dfc477cc6e27aa254450339109a8cca2dc4b81c5:

Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja.

Release / BUILD_TESTING=ON: built the selected test targets; 2 CTest cases, 0 failures, 0 CTest skips.

Tests: savedata_memory_metadata, savedata_memory_growth.

Reproduce after building the test targets: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^savedata_memory_(metadata|growth)$".

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: #1680's current head (6a7cce4) only rewrites the blob when it is missing or smaller than the request, so a smaller request no longer truncates it. If you find a case that still does, please reopen with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants