From 3ece17f201686342e8aff90148f360245788b234 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Tue, 3 Mar 2020 21:25:56 -0800 Subject: add support for puzzle serialization --- Source/PuzzleSerializer.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/PuzzleSerializer.cpp') diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 3732db8..e316216 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp @@ -179,6 +179,7 @@ void PuzzleSerializer::ReadExtras(Puzzle& p) { void PuzzleSerializer::ReadDecorations(Puzzle& p, int id) { int numDecorations = _memory->ReadEntityData(id, NUM_DECORATIONS, 1)[0]; + if (numDecorations == 0) return; std::vector decorations = _memory->ReadArray(id, DECORATIONS, numDecorations); if (numDecorations > 0) p.hasDecorations = true; @@ -203,6 +204,7 @@ void PuzzleSerializer::ReadDecorations(Puzzle& p, int id) { void PuzzleSerializer::ReadSequence(Puzzle& p, int id) { int sequenceLength = _memory->ReadEntityData(id, SEQUENCE_LEN, 1)[0]; + if (sequenceLength == 0) return; std::vector sequence = _memory->ReadArray(id, SEQUENCE, sequenceLength); for (int location : sequence) { @@ -545,6 +547,8 @@ std::tuple PuzzleSerializer::loc_to_xy(const Puzzle& p, int location) int x = 2 * (location % width2); int y = 2 * (height2 - location / width2); + assert(x >= 0 && x < p.width); + assert(y >= 0 && y < p.height); return {x, y}; } -- cgit 1.4.1