jPCT-AE - a 3d engine for Android > Support

Problem with difference textures which have the same texture name

(1/2) > >>

kiffa:
I have a dog, in scene-1, the dog will be set to texture1 which named "dog".

In scene-2,  i first removeAndUnload("dog"), then new texture2 which is different from texture1 but has the same name "dog", then set the texture2 to the dog.

But the dog in scene-2 looks like with another texture which is not texture2.

Codes:


--- Code: ---//scene1
texture1 = new texture(in);
textManager.addTexture("dog", texture1);
dog.setTexture("dog");

//do something
...

//switch to scene2
removeAndUnload("dog");

//in scene2
//add some other texture first
textureManager.addTexture("some other textures")

//new texture2 with the same name "dog"
texture2 = new texture(in2);
textureManager.addTexture("dog", texture2);

dog.setTexture("dog");

// the dog seems not to be set to  the texture2, but one of "some other textures"
--- End code ---

I guess that was caused by some caching mechanism?










EgonOlsen:
Try to use replaceTexture in the TextureManager instead to create a new texture of the same name.

kiffa:
Should i unload the texture which will be replaced?


--- Code: ---new texture1;
tm.addTexture("dog", texture1);
dog.setTexture("dog");

new texture2;

//Then
tm.unloadTexture("dog");
tm.replace("dog", texture2);

//Or just need
tm.replace("dog", texture2);  // the new texture wiil be auto upload to gpu, and the old one will be auto unloaded



--- End code ---

kiffa:
I don't want to hold the texture of the dog in memory(both vm and gpu) all the time because of the limited memory. I want to free the texture of the dog when switching to some scenes which don't need the dog.

But i need hold the object of dogModel(Animated3D) in memory all the time(by static reference)  because of the long model-loading time(So i want to just loading once).

So, if the texture name of my dog is always the same, and if i use TextureManager.replaceTextures(), which means i need hold the texture of the dog in memory all the time.

And if i free the texture in some situation,  then create it again later, dog.setTexture(theSameName) will cause an problem which i described above.

Any suggestion? Could i clear the texture cache of the dog by some methods?

EgonOlsen:
There's no cache or such thing. If you remove and unload a texture, it's gone. If it's still shown on the model, the model references some texture in gpu memory that is only still there because the memory hasn't been reused yet. I'm not sure what happens if you remove one and add another texture with same name later. I suggest to use replace instead. If you are worried about the memory, replace it with some very small dummy instead. I'll have a look why it behaves the way it does in your case.

Navigation

[0] Message Index

[#] Next page

Go to full version