- Fix crash when undoing connection with dummy junction.

This commit is contained in:
Tanasart 2024-07-25 17:04:48 +07:00
parent a5810b9345
commit 5d8f5c37d4
4 changed files with 33 additions and 21 deletions

View file

@ -43,7 +43,7 @@ function Action(_type, _object, _data, _trigger = 0) constructor {
clear_action = noone;
static undo = function() { #region
static undo = function() {
var _n;
switch(type) {
@ -85,8 +85,10 @@ function Action(_type, _object, _data, _trigger = 0) constructor {
break;
case ACTION_TYPE.junction_connect :
if(obj.is_dummy) {
data[0].setFrom(noone);
if(obj.dummy_undo != -1) obj.dummy_undo(data[0]);
} else {
var _d = obj.value_from;
obj.setFrom(data);
@ -154,9 +156,9 @@ function Action(_type, _object, _data, _trigger = 0) constructor {
}
if(trigger) trigger();
} #endregion
}
static redo = function() { #region
static redo = function() {
var _n;
switch(type) {
case ACTION_TYPE.var_modify :
@ -199,6 +201,7 @@ function Action(_type, _object, _data, _trigger = 0) constructor {
if(obj.is_dummy) {
obj.setFrom(data[1]);
data[0] = obj.dummy_target;
if(obj.dummy_redo != -1) obj.dummy_redo(data[0]);
} else {
var _d = obj.value_from;
obj.setFrom(data);
@ -244,9 +247,9 @@ function Action(_type, _object, _data, _trigger = 0) constructor {
}
if(trigger) trigger();
} #endregion
}
static toString = function() { #region
static toString = function() {
var ss = "";
switch(type) {
case ACTION_TYPE.var_modify :
@ -316,15 +319,15 @@ function Action(_type, _object, _data, _trigger = 0) constructor {
break;
}
return ss;
} #endregion
}
static destroy = function() { #region
static destroy = function() {
if(clear_action == noone) return;
clear_action(data);
} #endregion
}
}
function recordAction(_type, _object, _data = -1, _trigger = 0) { #region
function recordAction(_type, _object, _data = -1, _trigger = 0) {
if(IS_UNDOING) return noone;
if(LOADING) return noone;
if(UNDO_HOLDING) return noone;
@ -340,7 +343,7 @@ function recordAction(_type, _object, _data = -1, _trigger = 0) { #region
PANEL_MENU.undoUpdate();
return act;
} #endregion
}
function recordAction_variable_change(object, variable_name, variable_old_value, undo_label = "", _trigger = 0) {
INLINE
@ -349,7 +352,7 @@ function recordAction_variable_change(object, variable_name, variable_old_value,
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function mergeAction(act) { #region
function mergeAction(act) {
if(ds_stack_empty(UNDO_STACK)) {
ds_stack_push(UNDO_STACK, [ act ]);
PANEL_MENU.undoUpdate();
@ -359,9 +362,9 @@ function mergeAction(act) { #region
var _top = ds_stack_pop(UNDO_STACK);
array_push(_top, act);
ds_stack_push(UNDO_STACK, _top);
} #endregion
}
function UNDO() { #region
function UNDO() {
CALL("undo");
if(ds_stack_empty(UNDO_STACK)) return;
@ -376,9 +379,9 @@ function UNDO() { #region
ds_stack_push(REDO_STACK, actions);
PANEL_MENU.undoUpdate();
} #endregion
}
function REDO() { #region
function REDO() {
CALL("redo");
if(ds_stack_empty(REDO_STACK)) return;
@ -393,4 +396,4 @@ function REDO() { #region
ds_stack_push(UNDO_STACK, actions);
PANEL_MENU.undoUpdate();
} #endregion
}

View file

@ -198,7 +198,11 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
draw_dummy = false;
input_dummy = nodeValue("Add to group", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, 0);
input_dummy.is_dummy = true;
input_dummy.setDummy(function() /*=>*/ { var input = nodeBuild("Node_Group_Input", 0, 0, self); return input.inParent; },
function(_junc) /*=>*/ { _junc.from.destroy() }
);
input_dummy.onSetFrom = function(juncFrom) {
array_remove(juncFrom.value_to, input_dummy);
input_dummy.value_from = noone;

View file

@ -388,7 +388,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
if(auto_input) {
dummy_input = nodeValue("Add value", self, JUNCTION_CONNECT.input, dummy_type, 0)
.setDummy(function() { return createNewInput(); })
.setDummy(function() /*=>*/ {return createNewInput()})
.setVisible(false, true);
}

View file

@ -59,8 +59,10 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
tags = VALUE_TAG.none;
is_dummy = false;
dummy_get = noone;
is_dummy = false;
dummy_get = noone;
dummy_undo = -1;
dummy_redo = -1;
#endregion
#region ---- connection ----
@ -235,10 +237,13 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
/////============= META =============
static setDummy = function(get_node) { #region
static setDummy = function(get_node, _dummy_undo = -1, _dummy_redo = -1) { #region
is_dummy = true;
dummy_get = get_node;
dummy_undo = _dummy_undo;
dummy_redo = _dummy_redo;
return self;
} #endregion