summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangjianguo <zhangjianguo@gdi.com.cn>2022-11-29 09:10:45 +0800
committerzhangjianguo <zhangjianguo@gdi.com.cn>2022-11-30 09:25:26 +0800
commit8e1138d59a8873d4d1cd04051bd8b19bd34ce81d (patch)
treebe9438f5f17998f44989e1e5d9732bba6af6c843
parent4a82d71d7345d0dde4da2816fd489da1c303f580 (diff)
Prevent editor crash when deleting children of GraphNode
-rw-r--r--scene/gui/graph_node.cpp66
1 files changed, 37 insertions, 29 deletions
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 5df4c066e4..83c789f3d5 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -366,38 +366,46 @@ void GraphNode::_notification(int p_what) {
close_rect = Rect2();
}
- for (const KeyValue<int, Slot> &E : slot_info) {
- if (E.key < 0 || E.key >= cache_y.size()) {
- continue;
- }
- if (!slot_info.has(E.key)) {
- continue;
- }
- const Slot &s = slot_info[E.key];
- // Left port.
- if (s.enable_left) {
- Ref<Texture2D> p = port;
- if (s.custom_slot_left.is_valid()) {
- p = s.custom_slot_left;
+ if (get_child_count() > 0) {
+ for (const KeyValue<int, Slot> &E : slot_info) {
+ if (E.key < 0 || E.key >= cache_y.size()) {
+ continue;
}
- p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E.key]), s.color_left);
- }
- // Right port.
- if (s.enable_right) {
- Ref<Texture2D> p = port;
- if (s.custom_slot_right.is_valid()) {
- p = s.custom_slot_right;
+ if (!slot_info.has(E.key)) {
+ continue;
+ }
+ const Slot &s = slot_info[E.key];
+ // Left port.
+ if (s.enable_left) {
+ Ref<Texture2D> p = port;
+ if (s.custom_slot_left.is_valid()) {
+ p = s.custom_slot_left;
+ }
+ p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E.key]), s.color_left);
+ }
+ // Right port.
+ if (s.enable_right) {
+ Ref<Texture2D> p = port;
+ if (s.custom_slot_right.is_valid()) {
+ p = s.custom_slot_right;
+ }
+ p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E.key]), s.color_right);
}
- p->draw(get_canvas_item(), icofs + Point2(get_size().x - edgeofs, cache_y[E.key]), s.color_right);
- }
- // Draw slot stylebox.
- if (s.draw_stylebox) {
- Control *c = Object::cast_to<Control>(get_child(E.key));
- Rect2 c_rect = c->get_rect();
- c_rect.position.x = sb->get_margin(SIDE_LEFT);
- c_rect.size.width = w;
- draw_style_box(sb_slot, c_rect);
+ // Draw slot stylebox.
+ if (s.draw_stylebox) {
+ Control *c = Object::cast_to<Control>(get_child(E.key));
+ if (!c || !c->is_visible_in_tree()) {
+ continue;
+ }
+ if (c->is_set_as_top_level()) {
+ continue;
+ }
+ Rect2 c_rect = c->get_rect();
+ c_rect.position.x = sb->get_margin(SIDE_LEFT);
+ c_rect.size.width = w;
+ draw_style_box(sb_slot, c_rect);
+ }
}
}