Fix crash when loading saved tutorial worlds#1001
Open
MCbabel wants to merge 1 commit intosmartcmd:mainfrom
Open
Fix crash when loading saved tutorial worlds#1001MCbabel wants to merge 1 commit intosmartcmd:mainfrom
MCbabel wants to merge 1 commit intosmartcmd:mainfrom
Conversation
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.
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.
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.cppline 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.cppwas changed: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.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