@@ -260,6 +260,8 @@ PackedStringArray GraphEdit::get_configuration_warnings() const {
260260}
261261
262262Error 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+
263265 if (is_node_connected (p_from, p_from_port, p_to, p_to_port)) {
264266 return OK;
265267 }
@@ -313,6 +315,8 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
313315}
314316
315317void 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+
316320 for (const List<Ref<Connection>>::Element *E = connections.front (); E; E = E->next ()) {
317321 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) {
318322 connection_map[p_from].erase (E->get ());
@@ -356,6 +360,8 @@ void GraphEdit::_scroll_moved(double) {
356360}
357361
358362void GraphEdit::_update_scroll_offset () {
363+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
364+
359365 set_block_minimum_size_adjust (true );
360366
361367 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
524530}
525531
526532void 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+
527535 _update_graph_frame (p_frame);
528536
529537 minimap->queue_redraw ();
@@ -535,6 +543,7 @@ void GraphEdit::_graph_frame_autoshrink_changed(const Vector2 &p_new_minsize, Gr
535543void GraphEdit::_graph_element_moved (Node *p_node) {
536544 GraphElement *graph_element = Object::cast_to<GraphElement>(p_node);
537545 ERR_FAIL_NULL (graph_element);
546+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
538547
539548 minimap->queue_redraw ();
540549 queue_redraw ();
@@ -543,6 +552,7 @@ void GraphEdit::_graph_element_moved(Node *p_node) {
543552}
544553
545554void GraphEdit::_graph_node_slot_updated (int p_index, Node *p_node) {
555+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
546556 GraphNode *graph_node = Object::cast_to<GraphNode>(p_node);
547557 ERR_FAIL_NULL (graph_node);
548558
@@ -558,6 +568,8 @@ void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_node) {
558568}
559569
560570void GraphEdit::_graph_node_rect_changed (GraphNode *p_node) {
571+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
572+
561573 // Only invalidate the cache when zooming or the node is moved/resized in graph space.
562574 if (panner->is_panning ()) {
563575 return ;
@@ -566,7 +578,6 @@ void GraphEdit::_graph_node_rect_changed(GraphNode *p_node) {
566578 for (Ref<Connection> &c : connection_map[p_node->get_name ()]) {
567579 c->_cache .dirty = true ;
568580 }
569-
570581 connections_layer->queue_redraw ();
571582 callable_mp (this , &GraphEdit::_update_top_connection_layer).call_deferred ();
572583
@@ -623,7 +634,9 @@ void GraphEdit::add_child_notify(Node *p_child) {
623634 }
624635 graph_element->connect (" raise_request" , callable_mp (this , &GraphEdit::_ensure_node_order_from).bind (graph_element));
625636 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+ }
627640 graph_element->connect (SceneStringName (item_rect_changed), callable_mp ((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw));
628641
629642 graph_element->set_scale (Vector2 (zoom, zoom));
@@ -640,6 +653,7 @@ void GraphEdit::remove_child_notify(Node *p_child) {
640653 minimap = nullptr ;
641654 } else if (p_child == connections_layer) {
642655 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." );
643657 }
644658
645659 if (top_layer != nullptr && is_inside_tree ()) {
@@ -662,7 +676,9 @@ void GraphEdit::remove_child_notify(Node *p_child) {
662676 for (const Ref<Connection> &conn : connection_map[graph_node->get_name ()]) {
663677 conn->_cache .dirty = true ;
664678 }
665- connections_layer->queue_redraw ();
679+ if (connections_layer != nullptr && connections_layer->is_inside_tree ()) {
680+ connections_layer->queue_redraw ();
681+ }
666682 }
667683
668684 GraphFrame *frame = Object::cast_to<GraphFrame>(graph_element);
@@ -1690,6 +1706,8 @@ void GraphEdit::set_selected(Node *p_child) {
16901706}
16911707
16921708void GraphEdit::gui_input (const Ref<InputEvent> &p_ev) {
1709+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
1710+
16931711 ERR_FAIL_COND (p_ev.is_null ());
16941712 if (panner->gui_input (p_ev, warped_panning ? get_global_rect () : Rect2 ())) {
16951713 return ;
@@ -2025,6 +2043,8 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
20252043}
20262044
20272045void GraphEdit::_pan_callback (Vector2 p_scroll_vec, Ref<InputEvent> p_event) {
2046+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2047+
20282048 h_scrollbar->set_value (h_scrollbar->get_value () - p_scroll_vec.x );
20292049 v_scrollbar->set_value (v_scrollbar->get_value () - p_scroll_vec.y );
20302050
@@ -2040,6 +2060,8 @@ void GraphEdit::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputE
20402060}
20412061
20422062void 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+
20432065 for (Ref<Connection> &c : connection_map[p_from]) {
20442066 if (c->from_node == p_from && c->from_port == p_from_port && c->to_node == p_to && c->to_port == p_to_port) {
20452067 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
20562078}
20572079
20582080void GraphEdit::reset_all_connection_activity () {
2081+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2082+
20592083 bool changed = false ;
20602084 for (Ref<Connection> &conn : connections) {
20612085 if (conn->activity > 0 ) {
@@ -2070,6 +2094,8 @@ void GraphEdit::reset_all_connection_activity() {
20702094}
20712095
20722096void GraphEdit::clear_connections () {
2097+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2098+
20732099 for (Ref<Connection> &c : connections) {
20742100 c->_cache .line ->queue_free ();
20752101 }
@@ -2083,7 +2109,9 @@ void GraphEdit::clear_connections() {
20832109}
20842110
20852111void GraphEdit::force_connection_drag_end () {
2112+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
20862113 ERR_FAIL_COND_MSG (!connecting, " Drag end requested without active drag!" );
2114+
20872115 connecting = false ;
20882116 connecting_valid = false ;
20892117 minimap->queue_redraw ();
@@ -2113,6 +2141,8 @@ void GraphEdit::set_zoom(float p_zoom) {
21132141}
21142142
21152143void GraphEdit::set_zoom_custom (float p_zoom, const Vector2 &p_center) {
2144+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2145+
21162146 p_zoom = CLAMP (p_zoom, zoom_min, zoom_max);
21172147 if (zoom == p_zoom) {
21182148 return ;
@@ -2521,6 +2551,8 @@ bool GraphEdit::is_showing_arrange_button() const {
25212551}
25222552
25232553void GraphEdit::override_connections_shader (const Ref<Shader> &p_shader) {
2554+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2555+
25242556 connections_shader = p_shader;
25252557
25262558 _invalidate_connection_line_cache ();
@@ -2539,6 +2571,8 @@ void GraphEdit::_minimap_toggled() {
25392571}
25402572
25412573void GraphEdit::set_connection_lines_curvature (float p_curvature) {
2574+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2575+
25422576 lines_curvature = p_curvature;
25432577 _invalidate_connection_line_cache ();
25442578 connections_layer->queue_redraw ();
@@ -2550,7 +2584,9 @@ float GraphEdit::get_connection_lines_curvature() const {
25502584}
25512585
25522586void GraphEdit::set_connection_lines_thickness (float p_thickness) {
2587+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
25532588 ERR_FAIL_COND_MSG (p_thickness < 0 , " Connection lines thickness must be greater than or equal to 0." );
2589+
25542590 if (lines_thickness == p_thickness) {
25552591 return ;
25562592 }
@@ -2565,6 +2601,8 @@ float GraphEdit::get_connection_lines_thickness() const {
25652601}
25662602
25672603void GraphEdit::set_connection_lines_antialiased (bool p_antialiased) {
2604+ ERR_FAIL_NULL_MSG (connections_layer, " connections_layer is missing." );
2605+
25682606 if (lines_antialiased == p_antialiased) {
25692607 return ;
25702608 }
0 commit comments