texture mismatch

Started by guillaume, August 28, 2013, 08:30:27 AM

Previous topic - Next topic

guillaume

hi, I write a jpct program, where has many object3D. some times a random bug happened.
one object3D's texture becomes another object3D's texture.
when the program run, it may replace and unload texture , do you have any idea ?

EgonOlsen

Quote from: guillaume on August 28, 2013, 08:30:27 AM
when the program run, it may replace and unload texture...
What do you mean with that? That your app replaces and unloads textures at runtime?

guillaume

"What do you mean with that? That your app replaces and unloads textures at runtime?"
yes. I do this at runtime. because I want to do marquee effect,  generate texture at runtime.

EgonOlsen

Make sure that your don't do this in parallel to the rendering, i.e. do all unloads and replacements in onDrawFrame(). If that is ensured, try to set Config.unloadImmediately=true; and try again.

guillaume

yes, I do all unloads and replacements in onDrawFrame().
I will try make Config.unloadImmediately=true.  thanks.

kiffa

#5
I ran into the same problem before, and I suggest don't do like this:

TextureManager tm = TextureManager.getInstance();
    tm.addTexture("A", texture_1);
    obj.setTexture("A"); //set textureId to id_1
   
    //do other things, like adding other textures, etc...

    obj.setTexture("A");
    tm.removeAndUnload(frameBuffer, "A");
    tm.addTexture("A", texture_2); //add a new texture with the same name, and it has the id of id_2
   
    //will set to the same textureId id_1, and this may be incorrect; The correct one is id_2
    //maybe TextureManager.getTextureId(name) did some caching algorithms.
    obj.setTexture("A");
   
    //And then you will see the mismatched texture, because of the incorrect textureId.


But do like this:

    TextureManager tm = TextureManager.getInstance();
    tm.addTexture("A", texture_1);
    obj.setTexture("A"); //set textureId to id_1
   
    //do other things, like adding other textures, etc...
   
    tm.replaceTexture("A", texture_2);

guillaume

Quote from: kiffa on August 28, 2013, 02:47:02 PM
I ran into the same problem before, and I suggest don't do like this:

TextureManager tm = TextureManager.getInstance();
    tm.addTexture("A", texture_1);
    obj.setTexture("A"); //set textureId to id_1
   
    //do other things, like adding other textures, etc...

    obj.setTexture("A");
    tm.removeAndUnload(frameBuffer, "A");
    tm.addTexture("A", texture_2); //add a new texture with the same name, and it has the id of id_2
   
    //will set to the same textureId id_1, and this may be incorrect; The correct one is id_2
    //maybe TextureManager.getTextureId(name) did some caching algorithms.
    obj.setTexture("A");
   
    //And then you will see the mismatched texture, because of the incorrect textureId.


But do like this:

    TextureManager tm = TextureManager.getInstance();
    tm.addTexture("A", texture_1);
    obj.setTexture("A"); //set textureId to id_1
   
    //do other things, like adding other textures, etc...
   
    tm.replaceTexture("A", texture_2);


yes. but when we use replaceTexture we encounter OOM exception finally , do you have meet this problem ?

EgonOlsen

As the docs say:

Quote
It might be required to call unloadTexture() before to ensure that the old texture has been unloaded from the GPU in case it's no longer used somewhere else.

guillaume

after try Config.unloadImmediately=true, it seems that texture misatch disappear.
but occasionally, we encounter texture lost. the position texture should appear
shows blank. any idea ?

EgonOlsen

Textures don't get lost by itself. This can happen only if you remove/unload them. Are you doing this to the textures in question?

guillaume

Quote from: EgonOlsen on September 30, 2013, 08:44:03 AM
Textures don't get lost by itself. This can happen only if you remove/unload them. Are you doing this to the textures in question?
yes. we need to update  the textures' content, so we remove/unload/add them continuous. is this cause the problem ?

EgonOlsen

Yes, most likely. I don't know exactly how you are doing things, but what you can't do is to remove a texture, add another one with the same name and expect the objects to reflect this change. If an object uses a texture and that texture should be changed so that all objects using it will be using the new one, it's better to use TextureManager.replaceTexture for that. Remove (as well as unload) is suitable only for textures that aren't in use anymore, i.e. there are no active object that use them.

guillaume

Quote from: EgonOlsen on September 30, 2013, 12:09:26 PM
Yes, most likely. I don't know exactly how you are doing things, but what you can't do is to remove a texture, add another one with the same name and expect the objects to reflect this change. If an object uses a texture and that texture should be changed so that all objects using it will be using the new one, it's better to use TextureManager.replaceTexture for that. Remove (as well as unload) is suitable only for textures that aren't in use anymore, i.e. there are no active object that use them.
just with replaceTexture, the memory consumed gets more and more, and finally we get OOM.
is it OK for us to add unloadTexture after replaceTexture ?
ex.

      Texture oldTexture = ...
      TextureManager.replaceTexture(name, newTexture);
      TextureManager.unloadTexutre(fb,oldTexture);

EgonOlsen

Quote from: guillaume on October 08, 2013, 03:01:18 AM
is it OK for us to add unloadTexture after replaceTexture ?
Yes, should be ok.