diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 122750fb..a14f1546 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -662,6 +662,7 @@ class Runtime extends EventEmitter { continue; } if (this.threads[i].target === target) { + this.threads[i].isKilled = true; this._removeThread(this.threads[i]); } } diff --git a/src/engine/sequencer.js b/src/engine/sequencer.js index c8051c87..d5c79eae 100644 --- a/src/engine/sequencer.js +++ b/src/engine/sequencer.js @@ -69,6 +69,9 @@ class Sequencer { // Normal-mode thread: step. this.stepThread(activeThread); activeThread.warpTimer = null; + if (activeThread.isKilled) { + i--; // if the thread is removed from the list (killed), do not increase index + } } if (activeThread.status === Thread.STATUS_RUNNING) { numActiveThreads++; diff --git a/src/engine/thread.js b/src/engine/thread.js index 208ff1e9..3b8ce32b 100644 --- a/src/engine/thread.js +++ b/src/engine/thread.js @@ -30,6 +30,12 @@ class Thread { */ this.status = 0; /* Thread.STATUS_RUNNING */ + /** + * Whether the thread is killed in the middle of execution. + * @type {boolean} + */ + this.isKilled = false; + /** * Target of this thread. * @type {?Target}