Skip to content

Commit

Permalink
Fix: Prevent loading of forbidden GIF file from crashing a game loadi…
Browse files Browse the repository at this point in the history
…ng screen (#5769)
  • Loading branch information
AlexandreSi authored Oct 12, 2023
1 parent 645d533 commit 3878b93
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions GDJS/Runtime/pixi-renderers/pixi-image-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,27 @@ namespace gdjs {

logger.log('Loading texture for resource "' + resourceName + '"...');
const file = resource.file;
const texture = PIXI.Texture.from(
this._resourcesLoader.getFullUrl(file),
{
resourceOptions: {
// Note that using `false`
// to not having `crossorigin` at all would NOT work because the browser would taint the
// loaded resource so that it can't be read/used in a canvas (it's only working for display `<img>` on screen).
crossorigin: this._resourcesLoader.checkIfCredentialsRequired(file)
? 'use-credentials'
: 'anonymous',
},
}
).on('error', (error) => {
const url = this._resourcesLoader.getFullUrl(file);
const texture = PIXI.Texture.from(url, {
resourceOptions: {
// Note that using `false`
// to not having `crossorigin` at all would NOT work because the browser would taint the
// loaded resource so that it can't be read/used in a canvas (it's only working for display `<img>` on screen).
crossorigin: this._resourcesLoader.checkIfCredentialsRequired(file)
? 'use-credentials'
: 'anonymous',
},
}).on('error', (error) => {
logFileLoadingError(file, error);
});
if (!texture) {
throw new Error(
'Texture loading by PIXI returned nothing for file ' +
file +
' behind url ' +
url
);
}
applyTextureSettings(texture, resource);

this._loadedTextures.put(resourceName, texture);
Expand Down Expand Up @@ -358,6 +364,12 @@ namespace gdjs {
: 'anonymous',
});
const loadedTexture = await PIXI.Assets.load(resource.file);
if (!loadedTexture) {
throw new Error(
'Texture loading by PIXI returned nothing for file ' +
resource.file
);
}
this._loadedTextures.put(resource.name, loadedTexture);
// TODO What if 2 assets share the same file with different settings?
applyTextureSettings(loadedTexture, resource);
Expand Down

0 comments on commit 3878b93

Please sign in to comment.