@@ -260,6 +260,8 @@ PackedStringArray GraphEdit::get_configuration_warnings() const {
260
260
}
261
261
262
262
Error GraphEdit::connect_node (const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
263
+ ERR_FAIL_NULL_V_MSG (connections_layer, FAILED, " connections_layer is missing." );
264
+
263
265
if (is_node_connected (p_from, p_from_port, p_to, p_to_port)) {
264
266
return OK;
265
267
}
@@ -313,6 +315,8 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
313
315
}
314
316
315
317
void GraphEdit::disconnect_node (const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
318
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
319
+
316
320
for (const List<Ref<Connection>>::Element *E = connections.front (); E; E = E->next ()) {
317
321
if (E->get ()->from_node == p_from && E->get ()->from_port == p_from_port && E->get ()->to_node == p_to && E->get ()->to_port == p_to_port) {
318
322
connection_map[p_from].erase (E->get ());
@@ -356,6 +360,8 @@ void GraphEdit::_scroll_moved(double) {
356
360
}
357
361
358
362
void GraphEdit::_update_scroll_offset () {
363
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
364
+
359
365
set_block_minimum_size_adjust (true );
360
366
361
367
for (int i = 0 ; i < get_child_count (); i++) {
@@ -524,6 +530,8 @@ void GraphEdit::_graph_element_resize_request(const Vector2 &p_new_minsize, Node
524
530
}
525
531
526
532
void GraphEdit::_graph_frame_autoshrink_changed (const Vector2 &p_new_minsize, GraphFrame *p_frame) {
533
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
534
+
527
535
_update_graph_frame (p_frame);
528
536
529
537
minimap->queue_redraw ();
@@ -535,6 +543,7 @@ void GraphEdit::_graph_frame_autoshrink_changed(const Vector2 &p_new_minsize, Gr
535
543
void GraphEdit::_graph_element_moved (Node *p_node) {
536
544
GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
537
545
ERR_FAIL_NULL (graph_element);
546
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
538
547
539
548
minimap->queue_redraw ();
540
549
queue_redraw ();
@@ -543,6 +552,7 @@ void GraphEdit::_graph_element_moved(Node *p_node) {
543
552
}
544
553
545
554
void GraphEdit::_graph_node_slot_updated (int p_index, Node *p_node) {
555
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
546
556
GraphNode *graph_node = Object::cast_to<GraphNode>(p_node);
547
557
ERR_FAIL_NULL (graph_node);
548
558
@@ -558,6 +568,8 @@ void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_node) {
558
568
}
559
569
560
570
void GraphEdit::_graph_node_rect_changed (GraphNode *p_node) {
571
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
572
+
561
573
// Only invalidate the cache when zooming or the node is moved/resized in graph space.
562
574
if (panner->is_panning ()) {
563
575
return ;
@@ -566,7 +578,6 @@ void GraphEdit::_graph_node_rect_changed(GraphNode *p_node) {
566
578
for (Ref<Connection> &c : connection_map[p_node->get_name ()]) {
567
579
c->_cache .dirty = true ;
568
580
}
569
-
570
581
connections_layer->queue_redraw ();
571
582
callable_mp (this , &GraphEdit::_update_top_connection_layer).call_deferred ();
572
583
@@ -623,7 +634,9 @@ void GraphEdit::add_child_notify(Node *p_child) {
623
634
}
624
635
graph_element->connect (" raise_request" , callable_mp (this , &GraphEdit::_ensure_node_order_from).bind (graph_element));
625
636
graph_element->connect (" resize_request" , callable_mp (this , &GraphEdit::_graph_element_resize_request).bind (graph_element));
626
- graph_element->connect (SceneStringName (item_rect_changed), callable_mp ((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
637
+ if (connections_layer != nullptr && connections_layer->is_inside_tree ()) {
638
+ graph_element->connect (SceneStringName (item_rect_changed), callable_mp ((CanvasItem *)connections_layer, &CanvasItem::queue_redraw));
639
+ }
627
640
graph_element->connect (SceneStringName (item_rect_changed), callable_mp ((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
628
641
629
642
graph_element->set_scale (Vector2 (zoom, zoom));
@@ -640,6 +653,7 @@ void GraphEdit::remove_child_notify(Node *p_child) {
640
653
minimap = nullptr ;
641
654
} else if (p_child == connections_layer) {
642
655
connections_layer = nullptr ;
656
+ WARN_PRINT (" GraphEdit's connection_layer removed. This should not be done. If you like to remove all GraphElements from a GraphEdit node, do not simply remove all non-internal children but check their type since the connection layer has to be kept non-internal due to technical reasons." );
643
657
}
644
658
645
659
if (top_layer != nullptr && is_inside_tree ()) {
@@ -662,7 +676,9 @@ void GraphEdit::remove_child_notify(Node *p_child) {
662
676
for (const Ref<Connection> &conn : connection_map[graph_node->get_name ()]) {
663
677
conn->_cache .dirty = true ;
664
678
}
665
- connections_layer->queue_redraw ();
679
+ if (connections_layer != nullptr && connections_layer->is_inside_tree ()) {
680
+ connections_layer->queue_redraw ();
681
+ }
666
682
}
667
683
668
684
GraphFrame *frame = Object::cast_to<GraphFrame>(graph_element);
@@ -1690,6 +1706,8 @@ void GraphEdit::set_selected(Node *p_child) {
1690
1706
}
1691
1707
1692
1708
void GraphEdit::gui_input (const Ref<InputEvent> &p_ev) {
1709
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
1710
+
1693
1711
ERR_FAIL_COND (p_ev.is_null ());
1694
1712
if (panner->gui_input (p_ev, warped_panning ? get_global_rect () : Rect2 ())) {
1695
1713
return ;
@@ -2025,6 +2043,8 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
2025
2043
}
2026
2044
2027
2045
void GraphEdit::_pan_callback (Vector2 p_scroll_vec, Ref<InputEvent> p_event) {
2046
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2047
+
2028
2048
h_scrollbar->set_value (h_scrollbar->get_value () - p_scroll_vec.x );
2029
2049
v_scrollbar->set_value (v_scrollbar->get_value () - p_scroll_vec.y );
2030
2050
@@ -2040,6 +2060,8 @@ void GraphEdit::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputE
2040
2060
}
2041
2061
2042
2062
void GraphEdit::set_connection_activity (const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
2063
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2064
+
2043
2065
for (Ref<Connection> &c : connection_map[p_from]) {
2044
2066
if (c->from_node == p_from && c->from_port == p_from_port && c->to_node == p_to && c->to_port == p_to_port) {
2045
2067
if (!Math::is_equal_approx (c->activity , p_activity)) {
@@ -2056,6 +2078,8 @@ void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_por
2056
2078
}
2057
2079
2058
2080
void GraphEdit::reset_all_connection_activity () {
2081
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2082
+
2059
2083
bool changed = false ;
2060
2084
for (Ref<Connection> &conn : connections) {
2061
2085
if (conn->activity > 0 ) {
@@ -2070,6 +2094,8 @@ void GraphEdit::reset_all_connection_activity() {
2070
2094
}
2071
2095
2072
2096
void GraphEdit::clear_connections () {
2097
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2098
+
2073
2099
for (Ref<Connection> &c : connections) {
2074
2100
c->_cache .line ->queue_free ();
2075
2101
}
@@ -2083,7 +2109,9 @@ void GraphEdit::clear_connections() {
2083
2109
}
2084
2110
2085
2111
void GraphEdit::force_connection_drag_end () {
2112
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2086
2113
ERR_FAIL_COND_MSG (!connecting, " Drag end requested without active drag!" );
2114
+
2087
2115
connecting = false ;
2088
2116
connecting_valid = false ;
2089
2117
minimap->queue_redraw ();
@@ -2113,6 +2141,8 @@ void GraphEdit::set_zoom(float p_zoom) {
2113
2141
}
2114
2142
2115
2143
void GraphEdit::set_zoom_custom (float p_zoom, const Vector2 &p_center) {
2144
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2145
+
2116
2146
p_zoom = CLAMP (p_zoom, zoom_min, zoom_max);
2117
2147
if (zoom == p_zoom) {
2118
2148
return ;
@@ -2521,6 +2551,8 @@ bool GraphEdit::is_showing_arrange_button() const {
2521
2551
}
2522
2552
2523
2553
void GraphEdit::override_connections_shader (const Ref<Shader> &p_shader) {
2554
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2555
+
2524
2556
connections_shader = p_shader;
2525
2557
2526
2558
_invalidate_connection_line_cache ();
@@ -2539,6 +2571,8 @@ void GraphEdit::_minimap_toggled() {
2539
2571
}
2540
2572
2541
2573
void GraphEdit::set_connection_lines_curvature (float p_curvature) {
2574
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2575
+
2542
2576
lines_curvature = p_curvature;
2543
2577
_invalidate_connection_line_cache ();
2544
2578
connections_layer->queue_redraw ();
@@ -2550,7 +2584,9 @@ float GraphEdit::get_connection_lines_curvature() const {
2550
2584
}
2551
2585
2552
2586
void GraphEdit::set_connection_lines_thickness (float p_thickness) {
2587
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2553
2588
ERR_FAIL_COND_MSG (p_thickness < 0 , " Connection lines thickness must be greater than or equal to 0." );
2589
+
2554
2590
if (lines_thickness == p_thickness) {
2555
2591
return ;
2556
2592
}
@@ -2565,6 +2601,8 @@ float GraphEdit::get_connection_lines_thickness() const {
2565
2601
}
2566
2602
2567
2603
void GraphEdit::set_connection_lines_antialiased (bool p_antialiased) {
2604
+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2605
+
2568
2606
if (lines_antialiased == p_antialiased) {
2569
2607
return ;
2570
2608
}
0 commit comments