HOTFIX: loading errors after the preload stage should not crash the game anymore
This commit is contained in:
parent
39a7b95e32
commit
0623ee0bf2
@ -59,9 +59,11 @@ export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, textur
|
||||
} else {
|
||||
returnPromise = Promise.resolve(texturekeys);
|
||||
}
|
||||
|
||||
//If the loading fail, we render the default model instead.
|
||||
return returnPromise.then((keys) => keys.map((key) => {
|
||||
return typeof key !== 'string' ? key.name : key;
|
||||
}))
|
||||
})).catch(() => lazyLoadPlayerCharacterTextures(loadPlugin, ["color_22", "eyes_23"]));
|
||||
}
|
||||
|
||||
export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptionInterface): BodyResourceDescriptionInterface => {
|
||||
@ -80,11 +82,25 @@ export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptio
|
||||
}
|
||||
|
||||
export const createLoadingPromise = (loadPlugin: LoaderPlugin, playerResourceDescriptor: BodyResourceDescriptionInterface, frameConfig: FrameConfig) => {
|
||||
return new Promise<BodyResourceDescriptionInterface>((res) => {
|
||||
return new Promise<BodyResourceDescriptionInterface>((res, rej) => {
|
||||
console.log('count', loadPlugin.listenerCount('loaderror'));
|
||||
if (loadPlugin.textureManager.exists(playerResourceDescriptor.name)) {
|
||||
return res(playerResourceDescriptor);
|
||||
}
|
||||
loadPlugin.spritesheet(playerResourceDescriptor.name, playerResourceDescriptor.img, frameConfig);
|
||||
loadPlugin.once('filecomplete-spritesheet-' + playerResourceDescriptor.name, () => res(playerResourceDescriptor));
|
||||
const errorCallback = (file: {src: string}) => {
|
||||
if (file.src !== playerResourceDescriptor.img) return;
|
||||
console.error('failed loading player ressource: ', playerResourceDescriptor)
|
||||
rej(playerResourceDescriptor);
|
||||
loadPlugin.off('filecomplete-spritesheet-' + playerResourceDescriptor.name, successCallback);
|
||||
loadPlugin.off('loaderror', errorCallback);
|
||||
}
|
||||
const successCallback = () => {
|
||||
loadPlugin.off('loaderror', errorCallback);
|
||||
res(playerResourceDescriptor);
|
||||
}
|
||||
|
||||
loadPlugin.once('filecomplete-spritesheet-' + playerResourceDescriptor.name, successCallback);
|
||||
loadPlugin.on('loaderror', errorCallback);
|
||||
});
|
||||
}
|
||||
|
@ -192,6 +192,7 @@ export class GameScene extends DirtyScene implements CenterListener {
|
||||
private pinchManager: PinchManager|undefined;
|
||||
private mapTransitioning: boolean = false; //used to prevent transitions happenning at the same time.
|
||||
private emoteManager!: EmoteManager;
|
||||
private preloading: boolean = true;
|
||||
|
||||
constructor(private room: Room, MapUrlFile: string, customKey?: string|undefined) {
|
||||
super({
|
||||
@ -259,11 +260,15 @@ export class GameScene extends DirtyScene implements CenterListener {
|
||||
return;
|
||||
}
|
||||
|
||||
this.scene.start(ErrorSceneName, {
|
||||
title: 'Network error',
|
||||
subTitle: 'An error occurred while loading resource:',
|
||||
message: this.originalMapUrl ?? file.src
|
||||
});
|
||||
//once preloading is over, we don't want loading errors to crash the game, so we need to disable this behavior after preloading.
|
||||
console.error('Error when loading: ', file);
|
||||
if (this.preloading) {
|
||||
this.scene.start(ErrorSceneName, {
|
||||
title: 'Network error',
|
||||
subTitle: 'An error occurred while loading resource:',
|
||||
message: this.originalMapUrl ?? file.src
|
||||
});
|
||||
}
|
||||
});
|
||||
this.load.on('filecomplete-tilemapJSON-'+this.MapUrlFile, (key: string, type: string, data: unknown) => {
|
||||
this.onMapLoad(data);
|
||||
@ -388,6 +393,7 @@ export class GameScene extends DirtyScene implements CenterListener {
|
||||
|
||||
//hook create scene
|
||||
create(): void {
|
||||
this.preloading = false;
|
||||
this.trackDirtyAnims();
|
||||
|
||||
gameManager.gameSceneIsCreated(this);
|
||||
|
Loading…
Reference in New Issue
Block a user