Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetLoader call onComplete only once #28

Closed
turbosqel opened this issue Mar 26, 2013 · 23 comments
Closed

AssetLoader call onComplete only once #28

turbosqel opened this issue Mar 26, 2013 · 23 comments

Comments

@turbosqel
Copy link

I have problem with using assetloader ,because when I refresh page it is not calling onComplete function .

@GoodBoyDigital
Copy link
Member

Thanks for the heads up! Seems to be the same issue as this: #13
Which browser are you using? Does the issue exist across all of your browsers? Thanks!

@turbosqel
Copy link
Author

Chrome 25 and Firefox 19 , it might be 'hasLoaded' problem :
var texture = PIXI.Texture.fromImage(filename);
if(!texture.hasLoaded)

but it should be probably : if(!texture.baseTexture.hasLoaded)

Im not sure , just hinting

@GoodBoyDigital
Copy link
Member

I agree, will take a poke around later today. Annoyingly I cant seem to recreate the issue on my current setup, would you mind testing the fix for me once its complete?

@turbosqel
Copy link
Author

Now Im 99% sure that this is an issue because this code works fine :

if (PIXI.Texture.fromImage("asset/shadow.png").baseTexture.hasLoaded) {
LoadComplete();
} else {
var loader = new PIXI.AssetLoader(["asset/1.jpg", "asset/js.png","asset/shadow.png"]);
loader.onComplete = LoadComplete;
loader.load();
}

Ok , I'll download latest when You fix it and give You feedback !

@piayo
Copy link

piayo commented Mar 26, 2013

from-cache
i think that cause is order of code.
img.onload=func after img.src="url" or,
img.src="url" after img.onload=func <- this was "from cache".

@turbosqel
Copy link
Author

yeah , but it must work anyway, cache or download :)

@GoodBoyDigital
Copy link
Member

Quick test :)

If you swap these two lines around in the PIXI.Texture.fromImage function:

image.src = imageUrl;
baseTexture = new PIXI.BaseTexture(image); 

like this:

baseTexture = new PIXI.BaseTexture(image);
image.src = imageUrl; 

does that fix the issue?

@piayo
Copy link

piayo commented Mar 26, 2013

baseTexture = new PIXI.BaseTexture(image);
image.src = imageUrl; 

and,

PIXI.BaseTexture = function(a) {
    this.height = this.width = 0;
    if (this.source instanceof Image)
        if (this.source.width) //"complete" property is buggy its always "true"

I think it is ok.

@turbosqel
Copy link
Author

Nope , but I was right about "hasLoaded" param . Please look at code :
https://github.com/GoodBoyDigital/pixi.js/blob/master/src/pixi/loaders/AssetLoader.js#L84

Texture object dont have property "hasLoaded" so (!texture.hasLoaded) will be always true and it try load and never end , but it should skip it . There must be :
if(!texture.textureBase.hasLoaded){...

and at end of function :
if(this.loadCount == 0){this.onAssetLoaded();};

This solved problem .

@GoodBoyDigital
Copy link
Member

Oh yes! you are absolutely correct 👍 Great catch!
piayo does turbosqel's solution work for you? Thanks both!

@turbosqel
Copy link
Author

Thats a pain of js . Im moving from as3 to js and no strong type can cause big headaches :) btw any plans of adding solid color graphic rects ?

@GoodBoyDigital
Copy link
Member

I hear that! I come from as3 land too :)
I do have plans for solid rects, they will probably be the first primitive I make.

@turbosqel
Copy link
Author

yeah , thats very usefull , just like starilng quads . I'll try also implement this in Your lib : http://turbosqel.pl/relativestarling/

@GoodBoyDigital
Copy link
Member

nice one 👍

@fernandodrumond
Copy link

Hello!

@turbosqel 's answer worked for me, just note that the code should be:

if(!texture.baseTexture.hasLoaded)

Copy and paste on the other code will give you an error. ;)

Please, let me know when this fix is added to the repo, so I can go back to work with the most recent version.

By the way, awesome library! Thanks a lot!

@turbosqel
Copy link
Author

Dont forget to add :
if(this.loadCount == 0){this.onAssetLoaded();};

on botton of "load()" function , because loader wont call onComplete without it

@fernandodrumond
Copy link

One more thing, the function PIXI.AssetLoader.prototype.onAssetLoaded

Should have

this.loadCount--;

replaced by

if(this.loadCount > 0){ this.loadCount--; }

Otherwise the comparison to 0 will return false if all assets are loaded (this.loadCount will be -1).

I was experiencing this problem on Firefox and it would only work after cleaning the cache.

@turbosqel
Copy link
Author

it should not happen , since loadCount is taken from toLoad array length . So it should loop and shift always to 0 .

@fernandodrumond
Copy link

On the code I had, there was a call to this.loadCount--; on the beginning of the method onAssetLoaded(), so a call to it with this.loadCount == 0 would make this.loadCount evaluate to -1.

@GoodBoyDigital
Copy link
Member

Should be all good now gents :)

@fernandodrumond
Copy link

Works fine for me now! Thanks!

@lock
Copy link

lock bot commented Feb 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants