Bolko

ressource already exists although removedFromCache

Recommended Posts

Hi,

 

I remove textures from the cache when I don´t need them any more:

PIXI.Texture.removeTextureFromCache(myTexture).destroy(true);

But when I later try to load them again, I get the following error:

 

post-11938-0-53463600-1431594338_thumb.j

 

although this:

PIXI.utils.TextureCache[myTexture]

is undefined

Share this post


Link to post
Share on other sites

Couple things here:

 

1) destroying a base texture removes it from the cache, you don't need to do it manually.

 

2) The error is completely unrelated to the PIXI cache. Looks like you use the loader, then try to use it again later.

 

The way the loader works is that it loads everything you tell it to and stores them in "loader.resources" so you can access them anytime you want. If you want to clear that out and get ready for a fresh load then just do "loader.reset()" and the loader is ready to load new resources! If you are just going to reload the same resources again, you don't have to. You can just use the "loader.resources" that already are there.

 

Remember that the loader and the util caches are completely separate.

Share this post


Link to post
Share on other sites

Ok thanks,

 

so 1) What exactly do you mean with I don´t need to remove the base texture manually?

Do you mean I should only do this without removeTextureFromCache()?

myTexture.destroy(true);

In my case I am loading big background images with the loader and add them to the stage.

When the user leaves a Room, I´m loading a new bg image and destroy the old image to avoid memory problems.

To free the memory it would be best to also reset the loader, right?

When the loader has loaded an Image it is in the TextureCache anyway, so no need to leave it in the loader?

Share this post


Link to post
Share on other sites

Ok thanks,

 

so 1) What exactly do you mean with I don´t need to remove the base texture manually?

Do you mean I should only do this without removeTextureFromCache()?

myTexture.destroy(true);

In my case I am loading big background images with the loader and add them to the stage.

When the user leaves a Room, I´m loading a new bg image and destroy the old image to avoid memory problems.

To free the memory it would be best to also reset the loader, right?

When the loader has loaded an Image it is in the TextureCache anyway, so no need to leave it in the loader?

 

Correct, the texture destroy method, when called with true, will call the baseTexture destroy method which cleans the utils cache as you can see in the links.

 

If memory is a concern, and you are using the pixi caches, you can just call loader.reset() when you no longer need to read the resources directly from the loader.

Share this post


Link to post
Share on other sites

well, I tried 

PIXI.utils.TextureCache[key].destroy(true);

But in my case it doesn´t do the job, because when I then try to load that image again (which i must when the user goes back to the previous room), it gives me

Uncaught TypeError: Cannot read property 'hasLoaded' of null                    // in Sprite.js:162
So I guess I´ll stick with
PIXI.Texture.removeTextureFromCache(key).destroy(true);

Nothing really wrong with that, is it?

Share this post


Link to post
Share on other sites

"Wrong", no its not wrong. But if just delete doesn't work for you then that is a bug, and I'd like to get to the bottom of it.

 

Can you give me a test case that reproduces the behavior you are describing? Just looking at the code I don't see why this would happen..

Share this post


Link to post
Share on other sites

The null reference happens when someone destroys a texture, including its base texture:

myTexture.destroy(true);

and then later on wishes to reload the texture with the loader, but first checks if the texture has already been loaded like so:

var texture = null;
var url = "myTextureURL.png";

var resource = PIXI.loader.resources;
if (resource) {
 texture = resource.texture;
}

At this point, the texture object, the same texture object that was cached in the PIXI texture cache, no longer has a baseTexture property - it's null.

Resetting the PIXI loader before attempting to load the texture each time solves the problem:


PIXI.loader.reset();

But it's not obvious that users should "reset" the PIXI loader.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.