From 45a2f426024e8221f4756f524f6bda93b5cc6a5f Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Thu, 17 Apr 2025 10:44:50 -0500 Subject: [PATCH] [Bug] Prevent game from hanging when loading in a new battle (#5676) --- src/field/pokemon.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index cdd48f7d940..ce36a40697b 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -840,12 +840,17 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { await Promise.allSettled(loadPromises); - // Wait for the assets we queued to load to finish loading, then... + // This must be initiated before we queue loading, otherwise the load could have finished before + // we reach the line of code that adds the listener, causing a deadlock. + const waitOnLoadPromise = new Promise(resolve => globalScene.load.once(Phaser.Loader.Events.COMPLETE, resolve)); + if (!globalScene.load.isLoading()) { globalScene.load.start(); } + + // Wait for the assets we queued to load to finish loading, then... // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#creating_a_promise_around_an_old_callback_api - await new Promise(resolve => globalScene.load.once(Phaser.Loader.Events.COMPLETE, resolve)); + await waitOnLoadPromise; // With the sprites loaded, generate the animation frame information if (this.isPlayer()) {