Android: texture flushing error when restarting
Monkey Forums/Monkey Bug Reports/Android: texture flushing error when restarting
| ||
UPDATE 2: Mark solved this problem in v61, please move on, nothing to see here :) UPDATE 1: scroll down to the proposed solution for v60 The app The app has a "cover" scene, followed by a "menu" scene. Cover scene loads one image only, animates it, and then loads the "menu" scene, which in turn loads whole bunch of additional images. The symptoms Case 1: (Step 1) Launch the app, let it load images, exit the app with finish() (Step 2) Re-launch the app -> one of the textures is assigned to a wrong Image in the second ("menu") scene. Case 2: (Step 1) Launch the app, let it load images, exit with System.exit(0) (Step 2) Re-launch the app -> everything is fine |
| ||
Here is my solution (applied to v60): (1) Add static int to MonkeyGame: [monkeycode] static int sessionId; [/monkeycode] (2) Increment sessionId in onCreate: [monkeycode] sessionId++; [/monkeycode] (3) Add a session id stamp to each gxtkSurface instance: [monkeycode] class gxtkSurface{ Bitmap bitmap; int sessionId; //' <--- here int width,height; boolean hasAlpha; int texId,seq; float uscale,vscale; static Vector discarded=new Vector(); gxtkSurface( Bitmap bitmap, String srcFile ){ this.bitmap=bitmap; this.sessionId = MonkeyGame.sessionId; //'<--- and here width=bitmap.getWidth(); height=bitmap.getHeight(); hasAlpha=bitmap.hasAlpha(); } } [/monkeycode] (4) And discard texture ONLY IF surface's sessionId equals current sessionId: [monkeycode] int Discard(){ if( bitmap!=null ){ bitmap=null; } if( texId!=0 && sessionId==MonkeyGame.sessionId){ //'<<--- here discarded.add( Integer.valueOf( texId ) ); texId=0; } return 0; } [/monkeycode] |
| ||
Hi, This is what the 'seq' field is supposed to do - it syncs the texId to a global 'valid context' seq counter. Note that the global seq can change even without the app finishing, eg: if the app is suspended/resumed all the graphics get lost, DX style (grr....). There's a callback for handling this - graphicsCreated or something - and that's where I bump the global seq. I do vaguely remember fixing something like thisin v61 though, although I was unable to reproduce it to test it - it just 'looked' wrong! Can you give the latest version of Monkey a try? |
| ||
I noticed app.seq, but wasn't sure if it can be used for this purpose. Indeed, when running my app with v63b, there is no problem with textures. Your new Invalidate() code did the trick: [monkeycode] void Invalidate(){ if( texId!=0 ){ if( seq==MonkeyGame.app.seq ) discarded.add( Integer.valueOf( texId ) ); texId=0; } } [/monkeycode] Please ignore this thread, I should upgrade more often :) |
| ||
Hi, Thanks for pointing it out anyway - kind of a coincidence we both stumbled across it at about the same time! |