Author Topic: clear data  (Read 4668 times)

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #15 on: August 08, 2011, 09:45:23 pm »
... only 4 running, the same.  :'(  I try
Code: [Select]
TextureManager tm = TextureManager.getInstance();
Set<String> names = tm.getNames();
if (names != null && !names.isEmpty()){
for (String name : names){
tm.removeTexture(name);
}
}
but then, when textures remove and next create command trying set their - throw exception about textures allredy exists.
How i can clear TM singleton ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: clear data
« Reply #16 on: August 08, 2011, 09:50:14 pm »
The question is: Why would you do that? Actually, you don't have to. Just load the textures once and don't touch the manager's content afterwards. Just make sure that you don't load them on each new surface creation. But to answer your question: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/TextureManager.html#flush(). Ignore the comment about applet in the Javadoc of that method. It's a porting flaw from desktop jPCT. I'll remove it.


Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #17 on: August 08, 2011, 09:56:39 pm »
dont help.
if use this removing
Code: [Select]
if (fb != null) {
System.out.println("************************************ remove textures");
TextureManager tm = TextureManager.getInstance();
Set<String> names = tm.getNames();
if (names != null && !names.isEmpty()){
for (String name : names){
tm.removeAndUnload(name, fb);
}
}
fb.dispose();
fb = null;
}

first after recreate -  ERROR: A texture with the name 'redCell' has been declared twice! -  (in try{}catch)
and second, when try set - ERROR: Tried to set an undefined texture as default!

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #18 on: August 08, 2011, 09:58:39 pm »
sorry, i don read your last replay, i try create once

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: clear data
« Reply #19 on: August 08, 2011, 10:01:08 pm »
You can actually do that for everything as long as you keep the references somewhere. There's no need to load objects and textures on each surface creation. The only thing that has to be recreated each time is the FrameBuffer because it takes the gl context and the orientation might have changed. But apart from that, jPCT-AE will take care to reuse your objects and textures in another context on another surface.

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #20 on: August 08, 2011, 10:08:19 pm »
in wallpaper service in oncreateEngine
Code: [Select]
texturesCreated = false;

 ...

if (!texturesCreated){
redCell = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.red_cell)), 64, 64));
blueCell = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.blue_cell)), 64, 64));
aNuc = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.nuc_a)), 64, 64));
tNuc = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.nuc_t)), 64, 64));
gNuc = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.nuc_g)), 64, 64));
cNuc = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.nuc_c)), 64, 64));
TextureManager.getInstance().addTexture("redCell", redCell);
TextureManager.getInstance().addTexture("blueCell", blueCell);
TextureManager.getInstance().addTexture("aNuc", aNuc);
TextureManager.getInstance().addTexture("tNuc", tNuc);
TextureManager.getInstance().addTexture("gNuc", gNuc);
TextureManager.getInstance().addTexture("cNuc", cNuc);
texturesCreated = true;
}
ERROR: Tried to set an undefined texture as default! - and because that i recreating rextures in onSurfaceCreated

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: clear data
« Reply #21 on: August 08, 2011, 10:13:44 pm »
I've no idea when you call onCreateEngine() or what you do when the app goes out of scope...but: If you upload the textures only once and never remove/unload/flush anything, then there is no need to reload them again. Just have a look at the examples that come with the engine: They don't do that! They load everything only once and keep it until the app gets destroyed by Android.

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #22 on: August 08, 2011, 10:14:16 pm »
sorry, i dont remove removing textures code, now 6 time without crash :) . Too late, i did not realize anything now, this wallpaper make me crazy :) I will continue tomorrow

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #23 on: August 15, 2011, 09:46:49 am »
I move all textures & world initialization to Engine.onCreate, in onDestroy clear world & textures, all work good, but, i worry that if on device installed 2 different applications and some textures has equals names?  TextureManager instance will be the same for both?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: clear data
« Reply #24 on: August 15, 2011, 10:33:14 am »
No, it's only a singleton per VM instance.

Offline Alexey

  • int
  • **
  • Posts: 50
    • View Profile
Re: clear data
« Reply #25 on: August 15, 2011, 11:29:21 am »
Ok, thank you for replies!