Skip to content

Fix crash when loading saved tutorial worlds#1001

Open
MCbabel wants to merge 1 commit intosmartcmd:mainfrom
MCbabel:fix/tutorial-save-schematic-crash
Open

Fix crash when loading saved tutorial worlds#1001
MCbabel wants to merge 1 commit intosmartcmd:mainfrom
MCbabel:fix/tutorial-save-schematic-crash

Conversation

@MCbabel
Copy link
Contributor

@MCbabel MCbabel commented Mar 9, 2026

Description

Fixes the crash when trying to load a saved tutorial world. Players would get the "Unrecognised schematic version!!" error every time they saved a tutorial world and tried to load it back.

Changes

Previous Behavior

If you played the tutorial world, saved it, left, and then tried to load that save again, the game would crash with an assertion error in ConsoleSchematicFile.cpp line 68.

Root Cause

When saving the game rules, writeRuleFile() wrote all the schematic file data into the stream but forgot to write how many files there are before the actual data. When loading, readRuleFile() tries to read that number first. Since it wasn't there, the reader grabbed the wrong bytes, got completely out of sync with the data, and eventually tried to load garbage as a schematic file — which hit the version check and crashed.

New Behavior

Tutorial saves load fine now. Old saves that were written before this fix are also handled correctly.

Fix Implementation

Only GameRuleManager.cpp was changed:

  1. Writing (line 347): Added dos->writeInt((int)files->size()) before the loop that writes schematic files, so the file count is actually in the stream now.

  2. Reading (lines 500–533): When loading from a save, the code reads the next int and checks if it makes sense as a file count (small number, ≤ 100). If the value is way too large, it's an old save without the count — in that case it rewinds the stream and reads the schematics one by one until it hits the xml-objects section. New saves and DLC files are still read normally.

Related Issues

writeRuleFile() was missing the schematic file count integer before the schematic entries. The reader in readRuleFile() expected this count, causing a stream misalignment that led to an assertion failure (Unrecognised schematic version) when reloading a saved tutorial world.

The fix writes the count on save and adds backward-compatible reading that detects old saves (without count) via a peek heuristic and falls back to count-less parsing.
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.

[Bug] Loading tutorial after saving and quitting world crashes game [Bug]: attempting to load tutorial saves crashes the game

1 participant