From f46f5d040671ccc2d948016f5f7a968a7f4f367a Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Mon, 1 Jun 2026 20:28:43 -0500 Subject: [PATCH] fix: ActionQueue used incorrect splice to remove (#3755) --- src/engine/actions/action-queue.ts | 4 +++- src/spec/vitest/action-spec.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/engine/actions/action-queue.ts b/src/engine/actions/action-queue.ts index e13c0cb6..afcb3f43 100644 --- a/src/engine/actions/action-queue.ts +++ b/src/engine/actions/action-queue.ts @@ -35,7 +35,9 @@ export class ActionQueue { */ public remove(action: Action) { const index = this._actions.indexOf(action); - this._actions.splice(index, 1); + if (index > -1) { + this._actions.splice(index, 1); + } } /** diff --git a/src/spec/vitest/action-spec.ts b/src/spec/vitest/action-spec.ts index 2236ce14..b3762fe8 100644 --- a/src/spec/vitest/action-spec.ts +++ b/src/spec/vitest/action-spec.ts @@ -1570,6 +1570,27 @@ describe('Action', () => { }); }); + describe('ActionQueue', () => { + it('does not remove last action when removing non-existent action', () => { + const queue = new ex.ActionQueue(actor); + const action1 = new ex.Delay(100); + const action2 = new ex.Delay(200); + const nonExistentAction = new ex.Delay(300); + + queue.add(action1); + queue.add(action2); + expect(queue.getActions().length).toBe(2); + + // Try to remove action that was never added + queue.remove(nonExistentAction); + + // Should still have both original actions + expect(queue.getActions().length).toBe(2); + expect(queue.getActions()).toContain(action1); + expect(queue.getActions()).toContain(action2); + }); + }); + describe('events', () => { it('emits actionstart event', () => { const spy = vi.fn(); -- 2.51.2