From 81b9702c6484ae23918a7a9670a069ac152a81a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pasteau?= <4895034+ClementPasteau@users.noreply.github.com> Date: Tue, 5 May 2026 15:03:23 +0200 Subject: [PATCH] Handle sounds stopped before loaded --- .../howler-sound-manager/howler-sound-manager.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts b/GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts index 01747f967f7c..3c77ff41f67d 100644 --- a/GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts +++ b/GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts @@ -105,6 +105,12 @@ namespace gdjs { */ private _rate: float; + /** + * Set to true when stop() is called so that a pending deferred play + * (scheduled via `once('load', ...)`) does not start the sound. + */ + private _stopped: boolean = false; + /** * An array of callbacks to call once the sound starts to play. */ @@ -179,7 +185,10 @@ namespace gdjs { this._oncePlay.forEach((func) => func(newID)); this._onPlay = []; this._oncePlay = []; - } else this._howl.once('load', () => this.play()); // Play only once the howl is fully loaded + } else + this._howl.once('load', () => { + if (!this._stopped) this.play(); + }); // Play only once the howl is fully loaded } catch (error) { handleHowlerSoundMethodError(error, 'play'); } @@ -205,6 +214,7 @@ namespace gdjs { */ stop(): this { try { + this._stopped = true; if (this._id !== null && this.isActualId()) this._howl.stop(this._id); } catch (error) { handleHowlerSoundMethodError(error, 'stop'); @@ -219,6 +229,7 @@ namespace gdjs { * to preload the sounds. */ playing(): boolean { + if (this._stopped) return false; const isSoundPlaying = this._id !== null ? this._howl.playing(this._id) : true; return (