clear data

Started by jms, December 10, 2010, 09:29:25 AM

Previous topic - Next topic

Alexey

... only 4 running, the same.  :'(  I try

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 ?

EgonOlsen

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.


Alexey

dont help.
if use this removing

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!

Alexey

sorry, i don read your last replay, i try create once

EgonOlsen

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.

Alexey

in wallpaper service in oncreateEngine

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

EgonOlsen

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.

Alexey

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

Alexey

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?

EgonOlsen

No, it's only a singleton per VM instance.

Alexey

Ok, thank you for replies!