From 94330dd2721ec50dca3d73377c774ba48d26b523 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Mon, 17 Jun 2024 12:07:47 +0700 Subject: [PATCH] - [Graph Panel] Fix crash when deleting multiple noeds. --- scripts/node_collection/node_collection.gml | 2 +- scripts/node_data/node_data.gml | 2 +- scripts/node_group_input/node_group_input.gml | 32 +++++++++++++++++++ scripts/panel_graph/panel_graph.gml | 11 +++++-- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/scripts/node_collection/node_collection.gml b/scripts/node_collection/node_collection.gml index bb3e06875..47ad100d3 100644 --- a/scripts/node_collection/node_collection.gml +++ b/scripts/node_collection/node_collection.gml @@ -576,7 +576,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc instanceBase = noone; } #endregion - static onDoubleClick = function(panel) { #region + function onDoubleClick(panel) { #region if(PREFERENCES.panel_graph_group_require_shift && !key_mod_press(SHIFT)) return false; __temp_panel = panel; diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index af941fe47..0fda5a123 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -2251,7 +2251,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { array_remove(group == noone? PROJECT.nodes : group.getNodeList(), self); if(PANEL_GRAPH.node_hover == self) PANEL_GRAPH.node_hover = noone; - PANEL_GRAPH.nodes_selecting = []; + array_remove(PANEL_GRAPH.nodes_selecting, self); if(PANEL_INSPECTOR.inspecting == self) PANEL_INSPECTOR.inspecting = noone; diff --git a/scripts/node_group_input/node_group_input.gml b/scripts/node_group_input/node_group_input.gml index c4bc7d6a2..db823c883 100644 --- a/scripts/node_group_input/node_group_input.gml +++ b/scripts/node_group_input/node_group_input.gml @@ -162,39 +162,53 @@ function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constru case "Range" : if(!is_array(_val) || array_length(_val) != 2) inParent.animator = new valueAnimator([0, 0], inParent); + + inParent.def_val = [0, 0]; inParent.setDisplay(VALUE_DISPLAY.range); break; case "Slider" : if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent); + + inParent.def_val = 0; inParent.setDisplay(VALUE_DISPLAY.slider, { range: [_range[0], _range[1], _step] }); break; case "Slider range" : if(!is_array(_val) || array_length(_val) != 2) inParent.animator = new valueAnimator([0, 0], inParent); + + inParent.def_val = [0, 0]; inParent.setDisplay(VALUE_DISPLAY.slider_range, { range: [_range[0], _range[1], _step] }); break; case "Rotation" : if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent); + + inParent.def_val = 0; inParent.setDisplay(VALUE_DISPLAY.rotation); break; case "Rotation range" : if(!is_array(_val) || array_length(_val) != 2) inParent.animator = new valueAnimator([0, 0], inParent); + + inParent.def_val = [0, 0]; inParent.setDisplay(VALUE_DISPLAY.rotation_range); break; case "Padding" : if(!is_array(_val) || array_length(_val) != 4) inParent.animator = new valueAnimator([0, 0, 0, 0], inParent); + + inParent.def_val = [0, 0, 0, 0]; inParent.setDisplay(VALUE_DISPLAY.padding); break; case "Area" : if(!is_array(_val) || array_length(_val) != 5) inParent.animator = new valueAnimator(DEF_AREA, inParent); + + inParent.def_val = array_clone(DEF_AREA); inParent.setDisplay(VALUE_DISPLAY.area); break; @@ -204,14 +218,20 @@ function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constru case 0 : if(!is_array(_val) || array_length(_val) != 2) inParent.animator = new valueAnimator([0, 0], inParent); + + inParent.def_val = [0, 0]; break; case 1 : if(!is_array(_val) || array_length(_val) != 3) inParent.animator = new valueAnimator([0, 0, 0], inParent); + + inParent.def_val = [0, 0, 0]; break; case 2 : if(!is_array(_val) || array_length(_val) != 4) inParent.animator = new valueAnimator([0, 0, 0, 0], inParent); + + inParent.def_val = [0, 0, 0, 0]; break; } if(_dtype == "Vector") inParent.setDisplay(VALUE_DISPLAY.vector); @@ -220,17 +240,23 @@ function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constru case "Enum button" : if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent); + + inParent.def_val = 0; inParent.setDisplay(VALUE_DISPLAY.enum_button, string_splice(_enum_label, ",")); break; case "Menu scroll" : if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent); + + inParent.def_val = 0; inParent.setDisplay(VALUE_DISPLAY.enum_scroll, string_splice(_enum_label, ",")); break; case "Palette" : if(!is_array(_val)) inParent.animator = new valueAnimator([c_black], inParent); + + inParent.def_val = [c_black]; inParent.setDisplay(VALUE_DISPLAY.palette); break; @@ -239,16 +265,22 @@ function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constru outputs[| 0].setType(inParent.type); inParent.animator = new valueAnimator(new gradientObject(c_white), inParent); + + inParent.def_val = new gradientObject(c_white); inParent.setDisplay(VALUE_DISPLAY._default); break; case "Curve": inParent.animator = new valueAnimator(CURVE_DEF_11, inParent); + + inParent.def_val = array_clone(CURVE_DEF_11); inParent.setDisplay(VALUE_DISPLAY.curve); break; default: if(is_array(_val)) inParent.animator = new valueAnimator(0, inParent); + + inParent.def_val = 0; inParent.setDisplay(VALUE_DISPLAY._default); break; } diff --git a/scripts/panel_graph/panel_graph.gml b/scripts/panel_graph/panel_graph.gml index bd1903142..9c826a216 100644 --- a/scripts/panel_graph/panel_graph.gml +++ b/scripts/panel_graph/panel_graph.gml @@ -1055,8 +1055,10 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { if(node_hovering != noone) _HOVERING_ELEMENT = node_hovering; - if(node_hovering != noone && _focus && DOUBLE_CLICK && node_hovering.onDoubleClick != -1) { + if(DOUBLE_CLICK) { + // print($"Double click {node_hovering} || {_focus} || {instanceof(node_hovering)}"); + if(node_hovering != noone && _focus && node_hovering.onDoubleClick != -1) if(node_hovering.onDoubleClick(self)) { DOUBLE_CLICK = false; node_hovering = noone; @@ -2405,7 +2407,12 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { function doDelete(_merge = false) { #region __temp_merge = _merge; - array_foreach(nodes_selecting, function(node) { if(node.manual_deletable) node.destroy(__temp_merge); }); + + for(i = array_length(nodes_selecting) - 1; i >= 0; i--) { + var _node = array_safe_get_fast(nodes_selecting, i, 0); + if(_node && _node.manual_deletable) + _node.destroy(__temp_merge); + } nodes_selecting = []; } #endregion