Skip to content

Commit

Permalink
When ImageFile loads with a linked Normal Map and the map completes…
Browse files Browse the repository at this point in the history
… first, but the Image is still in a pending state, it would incorrectly add itself to the cache instead of waiting. It now checks this process more carefully. Fix #5886
  • Loading branch information
photonstorm committed Nov 29, 2022
1 parent 0def5d1 commit 8b6b398
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/loader/filetypes/ImageFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,33 @@ var ImageFile = new Class({
*/
addToCache: function ()
{
// Check if we have a linked normal map
var linkFile = this.linkFile;

if (linkFile && linkFile.state >= CONST.FILE_COMPLETE)
if (linkFile)
{
if (this.type === 'image')
// We do, but has it loaded?
if (linkFile.state >= CONST.FILE_COMPLETE)
{
this.cache.addImage(this.key, this.data, linkFile.data);
}
else
{
this.cache.addImage(linkFile.key, linkFile.data, this.data);
// Both files have loaded
if (this.type === 'normalMap')
{
// linkFile.data = Image
// this.data = Normal Map
this.cache.addImage(this.key, linkFile.data, this.data);
}
else
{
// linkFile.data = Normal Map
// this.data = Image
this.cache.addImage(this.key, this.data, linkFile.data);
}
}

// Nothing to do here, we'll use the linkFile `addToCache` call
// to process this pair
}
else if (!linkFile)
else
{
this.cache.addImage(this.key, this.data);
}
Expand Down

0 comments on commit 8b6b398

Please sign in to comment.