From 7bab7fd7773854e136c7d2c31b83498fd35a4b2d Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Tue, 12 Mar 2019 03:17:30 +0100 Subject: [PATCH] Don't crash when the saved editor state contains fewer viewports than currently supported. --- editor/plugins/spatial_editor_plugin.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 776110b3b2e..ad945d7916d 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -4170,9 +4170,13 @@ void SpatialEditor::set_state(const Dictionary &p_state) { if (d.has("viewports")) { Array vp = d["viewports"]; - ERR_FAIL_COND(vp.size() > 4); + uint32_t vp_size = static_cast(vp.size()); + if (vp_size > VIEWPORTS_COUNT) { + WARN_PRINT("Ignoring superfluous viewport settings from spatial editor state.") + vp_size = VIEWPORTS_COUNT; + } - for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { + for (uint32_t i = 0; i < vp_size; i++) { viewports[i]->set_state(vp[i]); } }