I used your suggestion of calling Texture.defaultToKeepPixels(false) and loading the textures every time the context is lost, but now I'm getting:
java.lang.NullPointerException
at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2139)
at com.threed.jpct.World.draw(World.java:1321)
at com.threed.jpct.World.draw(World.java:1083)
at com.threed.jpct.util.SkyBox.render(SkyBox.java:201)
at com.wallpaper.MyRenderer.onDrawFrame(MyRenderer.java:238)
at net.rbgrn.android.glwallpaperservice.GLThread.guardedRun(GLWallpaperService.java:627)
at net.rbgrn.android.glwallpaperservice.GLThread.run(GLWallpaperService.java:492)
and:
java.lang.RuntimeException: [ 1351899406641 ] - ERROR: A texture with the name 'back' has been declared twice!
at com.threed.jpct.Logger.log(Logger.java:189)
at com.threed.jpct.TextureManager.addTexture(TextureManager.java:138)
at com.wallpaper.MyRenderer.onSurfaceChanged(MyRenderer.java:133)
at net.rbgrn.android.glwallpaperservice.GLThread.guardedRun(GLWallpaperService.java:622)
at net.rbgrn.android.glwallpaperservice.GLThread.run(GLWallpaperService.java:492)
or this:
java.lang.RuntimeException: [ 1351899405201 ] - ERROR: Requested texture not found!
at com.threed.jpct.Logger.log(Logger.java:189)
at com.threed.jpct.TextureManager.getTexture(TextureManager.java:403)
at com.threed.jpct.util.SkyBox.(SkyBox.java:72)
at com.threed.jpct.util.SkyBox.(SkyBox.java:38)
at com.wallpaper.MyRenderer.onSurfaceChanged(MyRenderer.java:136)
at net.rbgrn.android.glwallpaperservice.GLThread.guardedRun(GLWallpaperService.java:622)
at net.rbgrn.android.glwallpaperservice.GLThread.run(GLWallpaperService.java:492)
Note that I call .flush() on the TextureManager before loading any texture, so I don't really have a clue about what's going on... and how come the errors are only triggered on some phones.
Here's the code I use in onSurfaceChanged():
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
Log.d(TAG, "onSurfaceChanged() called");
Resources res = mContext.getResources();
// Flush the texture manager
TextureManager tm = TextureManager.getInstance();
tm.flush(); // This should clear the references to the textures, shouldn't it ?
// Framebuffer setup
if (mFrameBuffer != null) mFrameBuffer.dispose();
mFrameBuffer = new FrameBuffer(gl, width, height);
mWidth = width;
mHeight = height;
// World setup
if (mWorld != null) mWorld.dispose();
mWorld = new World();
mWorld.setAmbientLight(16, 16, 16);
// Sky box setup
String texPrefix = mPreferences.getString("skybox", null);
for (String sufix : mSkyBoxTexSufix) { // mSkyBoxTexSufix is an array = {left, top, right....}
String name = texPrefix + "_" + sufix;
int id = res.getIdentifier(name, "drawable", mContext.getPackageName());
Log.d(TAG, "Loading new texture " + name);
Texture t = new Texture(res.getDrawable(id));
t.setMipmap(false);
tm.addTexture(sufix, t);
}
if (mSkyBox != null) mSkyBox.dispose();
mSkyBox = new SkyBox(1000);
....
MemoryHelper.compact();
}