Unverified Commit 201d5a7f by Rémi Verschelde Committed by GitHub

Merge pull request #39389 from akien-mga/packedscene-root-aint-got-parents

PackedScene: Prevent crash when root node has `parent` attribute
parents d9f0477d c080ec5d
...@@ -903,19 +903,19 @@ void EditorNode::_dialog_display_load_error(String p_file, Error p_error) { ...@@ -903,19 +903,19 @@ void EditorNode::_dialog_display_load_error(String p_file, Error p_error) {
if (p_error) { if (p_error) {
switch (p_error) { switch (p_error) {
case ERR_CANT_OPEN: { case ERR_CANT_OPEN: {
show_accept(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_file.get_file()), TTR("OK")); show_accept(vformat(TTR("Can't open file '%s'. The file could have been moved or deleted."), p_file.get_file()), TTR("OK"));
} break; } break;
case ERR_PARSE_ERROR: { case ERR_PARSE_ERROR: {
show_accept(vformat(TTR("Error while parsing '%s'."), p_file.get_file()), TTR("OK")); show_accept(vformat(TTR("Error while parsing file '%s'."), p_file.get_file()), TTR("OK"));
} break; } break;
case ERR_FILE_CORRUPT: { case ERR_FILE_CORRUPT: {
show_accept(vformat(TTR("Unexpected end of file '%s'."), p_file.get_file()), TTR("OK")); show_accept(vformat(TTR("Scene file '%s' appears to be invalid/corrupt."), p_file.get_file()), TTR("OK"));
} break; } break;
case ERR_FILE_NOT_FOUND: { case ERR_FILE_NOT_FOUND: {
show_accept(vformat(TTR("Missing '%s' or its dependencies."), p_file.get_file()), TTR("OK")); show_accept(vformat(TTR("Missing file '%s' or one its dependencies."), p_file.get_file()), TTR("OK"));
} break; } break;
default: { default: {
show_accept(vformat(TTR("Error while loading '%s'."), p_file.get_file()), TTR("OK")); show_accept(vformat(TTR("Error while loading file '%s'."), p_file.get_file()), TTR("OK"));
} break; } break;
} }
} }
...@@ -3254,13 +3254,13 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b ...@@ -3254,13 +3254,13 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
if (!new_scene) { if (!new_scene) {
sdata.unref(); sdata.unref();
_dialog_display_load_error(lpath, ERR_FILE_NOT_FOUND); _dialog_display_load_error(lpath, ERR_FILE_CORRUPT);
opening_prev = false; opening_prev = false;
if (prev != -1) { if (prev != -1) {
set_current_scene(prev); set_current_scene(prev);
editor_data.remove_scene(idx); editor_data.remove_scene(idx);
} }
return ERR_FILE_NOT_FOUND; return ERR_FILE_CORRUPT;
} }
if (p_set_inherited) { if (p_set_inherited) {
......
...@@ -98,6 +98,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { ...@@ -98,6 +98,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
} }
#endif #endif
parent = nparent; parent = nparent;
} else {
// i == 0 is root node. Confirm that it doesn't have a parent defined.
ERR_FAIL_COND_V_MSG(n.parent != -1, nullptr, vformat("Invalid scene: root node %s cannot specify a parent node.", snames[n.name]));
} }
Node *node = nullptr; Node *node = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment