Author Topic: texture mismatch  (Read 2974 times)

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
texture mismatch
« on: August 28, 2013, 08:30:27 am »
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
    • http://www.jpct.net
Re: texture mismatch
« Reply #1 on: August 28, 2013, 09:36:30 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?

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: texture mismatch
« Reply #2 on: August 28, 2013, 12:15:57 pm »
"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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
    • http://www.jpct.net
Re: texture mismatch
« Reply #3 on: August 28, 2013, 12:30:31 pm »
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.

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: texture mismatch
« Reply #4 on: August 28, 2013, 12:57:36 pm »
yes, I do all unloads and replacements in onDrawFrame().
I will try make Config.unloadImmediately=true.  thanks.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: texture mismatch
« Reply #5 on: August 28, 2013, 02:47:02 pm »
I ran into the same problem before, and I suggest don't do like this:

Code: [Select]
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:

Code: [Select]
    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);
« Last Edit: August 28, 2013, 03:01:37 pm by kiffa »

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: texture mismatch
« Reply #6 on: August 29, 2013, 05:10:57 am »
I ran into the same problem before, and I suggest don't do like this:

Code: [Select]
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:

Code: [Select]
    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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
    • http://www.jpct.net
Re: texture mismatch
« Reply #7 on: August 29, 2013, 08:36:08 am »
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.

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: texture mismatch
« Reply #8 on: September 30, 2013, 04:45:13 am »
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
    • http://www.jpct.net
Re: texture mismatch
« Reply #9 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?

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: texture mismatch
« Reply #10 on: September 30, 2013, 11:12:01 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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
    • http://www.jpct.net
Re: texture mismatch
« Reply #11 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.

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: texture mismatch
« Reply #12 on: October 08, 2013, 03:01:18 am »
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.
Code: [Select]
      Texture oldTexture = ...
      TextureManager.replaceTexture(name, newTexture);
      TextureManager.unloadTexutre(fb,oldTexture);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12110
    • View Profile
    • http://www.jpct.net
Re: texture mismatch
« Reply #13 on: October 08, 2013, 09:13:14 am »
is it OK for us to add unloadTexture after replaceTexture ?
Yes, should be ok.