Skip to content

Commit 867b36e

Browse files
committed
fix #448: Do not load monitor dimensions if they're not present
1 parent ebd7882 commit 867b36e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/internal/scratch3reader.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,16 @@ bool Scratch3Reader::load()
404404
}
405405

406406
// width
407-
READER_STEP(step, "monitor -> width");
408-
monitor->setWidth(jsonMonitor["width"]);
407+
if (jsonMonitor.contains("width")) {
408+
READER_STEP(step, "monitor -> width");
409+
monitor->setWidth(jsonMonitor["width"]);
410+
}
409411

410412
// height
411-
READER_STEP(step, "monitor -> height");
412-
monitor->setHeight(jsonMonitor["height"]);
413+
if (jsonMonitor.contains("height")) {
414+
READER_STEP(step, "monitor -> height");
415+
monitor->setHeight(jsonMonitor["height"]);
416+
}
413417

414418
// x
415419
READER_STEP(step, "monitor -> x");

test/load_project/load_project_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,11 @@ TEST(LoadProjectTest, ProjectInvalidTest)
701701
ASSERT_EQ(p.scratchVersion(), ScratchVersion::Invalid);
702702
ASSERT_FALSE(p.load());
703703
}
704+
705+
TEST(LoadProjectTest, LoadNullDimensionMonitor)
706+
{
707+
// Regtest for #448
708+
std::string name = "regtest_projects/448_null_monitor_dimension.sb3";
709+
Project p(name);
710+
ASSERT_TRUE(p.load());
711+
}
Binary file not shown.

0 commit comments

Comments
 (0)