Bolko Posted May 14, 2015 Share Posted May 14, 2015 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: although this:PIXI.utils.TextureCache[myTexture]is undefined Quote Link to comment Share on other sites More sharing options...
xerver Posted May 14, 2015 Share Posted May 14, 2015 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. Quote Link to comment Share on other sites More sharing options...
Bolko Posted May 14, 2015 Author Share Posted May 14, 2015 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? Quote Link to comment Share on other sites More sharing options...
xerver Posted May 14, 2015 Share Posted May 14, 2015 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. Quote Link to comment Share on other sites More sharing options...
Bolko Posted May 14, 2015 Author Share Posted May 14, 2015 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 meUncaught TypeError: Cannot read property 'hasLoaded' of null // in Sprite.js:162So I guess I´ll stick withPIXI.Texture.removeTextureFromCache(key).destroy(true);Nothing really wrong with that, is it? Quote Link to comment Share on other sites More sharing options...
xerver Posted May 15, 2015 Share Posted May 15, 2015 "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.. Quote Link to comment Share on other sites More sharing options...
NintendoBen Posted March 25, 2016 Share Posted March 25, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.