Browse Source

Fix situation where TSCN format might crash, closes #3062

Juan Linietsky 9 years ago
parent
commit
f2ae6f87a4
2 changed files with 14 additions and 7 deletions
  1. 4 1
      scene/resources/packed_scene.h
  2. 10 6
      scene/resources/scene_format_text.cpp

+ 4 - 1
scene/resources/packed_scene.h

@@ -50,7 +50,6 @@ class SceneState : public Reference {
 		FLAG_INSTANCE_IS_PLACEHOLDER=(1<<30),
 		FLAG_MASK=(1<<24)-1,
 		NO_PARENT_SAVED=0x7FFFFFFF,
-		TYPE_INSTANCED=0x7FFFFFFF,
 
 	};
 
@@ -106,6 +105,10 @@ class SceneState : public Reference {
 	static bool disable_placeholders;
 public:
 
+	enum {
+		TYPE_INSTANCED=0x7FFFFFFF
+	};
+
 	static void set_disable_placeholders(bool p_disable);
 
 	int find_node_by_path(const NodePath& p_node) const;

+ 10 - 6
scene/resources/scene_format_text.cpp

@@ -362,18 +362,15 @@ Error ResourceInteractiveLoaderText::poll() {
 			parent=packed_scene->get_state()->add_node_path(next_tag.fields["parent"]);
 		}
 
-		if (next_tag.fields.has("owner")) {
-			owner=packed_scene->get_state()->add_node_path(next_tag.fields["owner"]);
-		} else {
-			if (parent!=-1)
-				owner=0; //if no owner, owner is root
-		}
 
 
 		if (next_tag.fields.has("type")) {
 			type=packed_scene->get_state()->add_name(next_tag.fields["type"]);
+		} else {
+			type=SceneState::TYPE_INSTANCED; //no type? assume this was instanced
 		}
 
+
 		if (next_tag.fields.has("instance")) {
 
 			instance=packed_scene->get_state()->add_value(next_tag.fields["instance"]);
@@ -384,6 +381,13 @@ Error ResourceInteractiveLoaderText::poll() {
 			}
 		}
 
+		if (next_tag.fields.has("owner")) {
+			owner=packed_scene->get_state()->add_node_path(next_tag.fields["owner"]);
+		} else {
+			if (parent!=-1 && !(type==SceneState::TYPE_INSTANCED && instance==-1))
+				owner=0; //if no owner, owner is root
+		}
+
 		int node_id = packed_scene->get_state()->add_node(parent,owner,type,name,instance);