Skip to content

Commit 7d214c6

Browse files
author
tamat
committed
fix in deferred events system
1 parent 1f3b786 commit 7d214c6

File tree

5 files changed

+118
-98
lines changed

5 files changed

+118
-98
lines changed

build/litegraph.core.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@
10731073
for (var i = 0; i < num; i++) {
10741074
for (var j = 0; j < limit; ++j) {
10751075
var node = nodes[j];
1076+
node.executePendingActions();
10761077
if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
10771078
//wrap node.onExecute();
10781079
node.doExecute();
@@ -1094,6 +1095,7 @@
10941095
for (var i = 0; i < num; i++) {
10951096
for (var j = 0; j < limit; ++j) {
10961097
var node = nodes[j];
1098+
node.executePendingActions();
10971099
if (node.mode == LiteGraph.ALWAYS && node.onExecute) {
10981100
node.onExecute();
10991101
}
@@ -3190,10 +3192,26 @@
31903192
this.mode = modeTo;
31913193
return true;
31923194
};
3195+
3196+
/**
3197+
* Triggers the execution of actions that were deferred when the action was triggered
3198+
* @method executePendingActions
3199+
*/
3200+
LGraphNode.prototype.executePendingActions = function() {
3201+
if(!this._waiting_actions || !this._waiting_actions.length)
3202+
return;
3203+
for(var i = 0; i < this._waiting_actions.length;++i)
3204+
{
3205+
var p = this._waiting_actions[i];
3206+
this.onAction(p[0],p[1],p[2],p[3],p[4]);
3207+
}
3208+
this._waiting_actions.length = 0;
3209+
}
3210+
31933211

31943212
/**
31953213
* Triggers the node code execution, place a boolean/counter to mark the node as being executed
3196-
* @method execute
3214+
* @method doExecute
31973215
* @param {*} param
31983216
* @param {*} options
31993217
*/
@@ -3204,13 +3222,6 @@
32043222
// enable this to give the event an ID
32053223
if (!options.action_call) options.action_call = this.id+"_exec_"+Math.floor(Math.random()*9999);
32063224

3207-
if(this._waiting_actions && this._waiting_actions.length)
3208-
for(var i = 0; i < this._waiting_actions.length;++i)
3209-
{
3210-
var p = this._waiting_actions[i];
3211-
this.onAction(p[0],p[1],p[2],p[3],p[4]);
3212-
}
3213-
32143225
this.graph.nodes_executing[this.id] = true; //.push(this.id);
32153226

32163227
this.onExecute(param, options);
@@ -3225,12 +3236,6 @@
32253236
}
32263237
}
32273238
else {
3228-
if(this._waiting_actions && this._waiting_actions.length)
3229-
for(var i = 0; i < this._waiting_actions.length;++i)
3230-
{
3231-
var p = this._waiting_actions[i];
3232-
this.onAction(p[0],p[1],p[2],p[3],p[4]);
3233-
}
32343239
}
32353240
this.execute_triggered = 2; // the nFrames it will be used (-- each step), means "how old" is the event
32363241
if(this.onAfterExecuteNode) this.onAfterExecuteNode(param, options); // callback

0 commit comments

Comments
 (0)