Browse Source

Prevent crash when clicking Mesh in MeshInstance when is scene root

hilfazer 4 years ago
parent
commit
84a9efcebc
2 changed files with 9 additions and 3 deletions
  1. 8 2
      editor/plugins/spatial_editor_plugin.cpp
  2. 1 1
      scene/main/node.cpp

+ 8 - 2
editor/plugins/spatial_editor_plugin.cpp

@@ -532,7 +532,10 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
 			continue;
 			continue;
 
 
 		if (dist < closest_dist) {
 		if (dist < closest_dist) {
-			item = edited_scene->get_deepest_editable_node(Object::cast_to<Node>(spat));
+			item = Object::cast_to<Node>(spat);
+			if (item != edited_scene) {
+				item = edited_scene->get_deepest_editable_node(item);
+			}
 
 
 			closest = item->get_instance_id();
 			closest = item->get_instance_id();
 			closest_dist = dist;
 			closest_dist = dist;
@@ -687,7 +690,10 @@ void SpatialEditorViewport::_select_region() {
 		if (!sp || _is_node_locked(sp))
 		if (!sp || _is_node_locked(sp))
 			continue;
 			continue;
 
 
-		Node *item = edited_scene->get_deepest_editable_node(Object::cast_to<Node>(sp));
+		Node *item = Object::cast_to<Node>(sp);
+		if (item != edited_scene) {
+			item = edited_scene->get_deepest_editable_node(item);
+		}
 
 
 		// Replace the node by the group if grouped
 		// Replace the node by the group if grouped
 		if (item->is_class("Spatial")) {
 		if (item->is_class("Spatial")) {

+ 1 - 1
scene/main/node.cpp

@@ -1929,7 +1929,7 @@ bool Node::is_editable_instance(const Node *p_node) const {
 
 
 Node *Node::get_deepest_editable_node(Node *p_start_node) const {
 Node *Node::get_deepest_editable_node(Node *p_start_node) const {
 	ERR_FAIL_NULL_V(p_start_node, nullptr);
 	ERR_FAIL_NULL_V(p_start_node, nullptr);
-	ERR_FAIL_COND_V(!is_a_parent_of(p_start_node), nullptr);
+	ERR_FAIL_COND_V(!is_a_parent_of(p_start_node), p_start_node);
 
 
 	Node const *iterated_item = p_start_node;
 	Node const *iterated_item = p_start_node;
 	Node *node = p_start_node;
 	Node *node = p_start_node;