[Bug] Prevent game from hanging when loading in a new battle (#5676)

This commit is contained in:
Sirz Benjie 2025-04-17 10:44:50 -05:00 committed by GitHub
parent b2bab46e1c
commit 45a2f42602
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -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<void>(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()) {