Selaa lähdekoodia

Prevent signal disconnection attempts on invalid references

Yuri Sizov 4 vuotta sitten
vanhempi
commit
6b13c8482a
1 muutettua tiedostoa jossa 16 lisäystä ja 3 poistoa
  1. 16 3
      scene/gui/graph_edit.cpp

+ 16 - 3
scene/gui/graph_edit.cpp

@@ -414,7 +414,14 @@ void GraphEdit::remove_child_notify(Node *p_child) {
 
 
 	Control::remove_child_notify(p_child);
 	Control::remove_child_notify(p_child);
 
 
-	if (is_inside_tree()) {
+	if (p_child == top_layer) {
+		top_layer = nullptr;
+		minimap = nullptr;
+	} else if (p_child == connections_layer) {
+		connections_layer = nullptr;
+	}
+
+	if (top_layer != nullptr && is_inside_tree()) {
 		top_layer->call_deferred("raise"); // Top layer always on top!
 		top_layer->call_deferred("raise"); // Top layer always on top!
 	}
 	}
 
 
@@ -422,8 +429,14 @@ void GraphEdit::remove_child_notify(Node *p_child) {
 	if (gn) {
 	if (gn) {
 		gn->disconnect("offset_changed", this, "_graph_node_moved");
 		gn->disconnect("offset_changed", this, "_graph_node_moved");
 		gn->disconnect("raise_request", this, "_graph_node_raised");
 		gn->disconnect("raise_request", this, "_graph_node_raised");
-		gn->disconnect("item_rect_changed", connections_layer, "update");
-		gn->disconnect("item_rect_changed", minimap, "update");
+
+		// In case of the whole GraphEdit being destroyed these references can already be freed.
+		if (connections_layer != nullptr && connections_layer->is_inside_tree()) {
+			gn->disconnect("item_rect_changed", connections_layer, "update");
+		}
+		if (minimap != nullptr && minimap->is_inside_tree()) {
+			gn->disconnect("item_rect_changed", minimap, "update");
+		}
 	}
 	}
 }
 }