Blitting Image using TexturePack

Started by JKumar, October 22, 2010, 01:35:25 PM

Previous topic - Next topic

JKumar

HI,

      I created a texture and added a single image only for testing.

TexturePack Creation:

TexturePack mTexturePack = new TexturePack();   
int imageId = mTexturePack.addImage(((BitmapDrawable)getResources().getDrawable(R.drawable.center)).getBitmap());

Using the TexturePack
When i am using in the draw as following -

mTexturePack.blit(fb, imageId, 100, 100, true);

Nothing is displaying on the screen and also its getting out of memory. See the log below-

java.lang.OutOfMemoryError
     at com.threed.jpct.VisList.<init>(VisList.java:51)
    at com.threed.jpct.VisListManager.getVisList(VisListManager.java:59)
     at com.threed.jpct.World.renderScene(World.java:1000)
    at android.thearena.Game_old$Renderer.onDrawFrame(Game_old.java:497)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1341)
     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)


What i am doing wrong ?
                  
         

raft

unless you arent creating TexturePack every frame, this has nothing to do with TexturePack.
what is the size (dimensions) of your image?

JKumar

Hi,

       My Image size is 8KB only and i am creating the texture pack object only in the onCreate method and not in the onDrawFrame method

I also getting the following before the Exception-

10-22 11:31:56.253: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.272: INFO/jPCT-AE(4493): Additional visibility list (2) created with size: 5000
10-22 11:31:56.292: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.322: INFO/jPCT-AE(4493): Additional visibility list (3) created with size: 5000
10-22 11:31:56.332: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.342: INFO/jPCT-AE(4493): Additional visibility list (4) created with size: 5000
10-22 11:31:56.352: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.363: INFO/jPCT-AE(4493): Additional visibility list (5) created with size: 5000
10-22 11:31:56.373: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.383: INFO/jPCT-AE(4493): Additional visibility list (6) created with size: 5000
10-22 11:31:56.392: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.412: INFO/jPCT-AE(4493): Additional visibility list (7) created with size: 5000
10-22 11:31:56.422: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.442: INFO/jPCT-AE(4493): Additional visibility list (8) created with size: 5000
10-22 11:31:56.462: INFO/jPCT-AE(4493): Drawing thread terminated!
10-22 11:31:56.462: INFO/dalvikvm(4493): Total arena pages for JIT: 12
10-22 11:31:56.482: INFO/ActivityManager(92): Displayed activity android.thearena/.Game_old: 2284 ms (total 2284 ms)
10-22 11:31:56.492: INFO/jPCT-AE(4493): Additional visibility list (9) created with size: 5000
10-22 11:31:56.502: INFO/jPCT-AE(4493): Drawing thread terminated!

JKumar


raft

i'm not sure what is going on here but this is not related to TexturePack.
comment the blitting line and check same error happens

EgonOlsen

You are creating VisLists as if there's no tomorrow until you run into an OOM. This can happen if you omit the call to display() for example. Judging from the "Drawing thread terminated!" message, your app is based on the sample code in the wiki. That code swallows the exception on the drawing thread, because it was meant to handle the "app stops, renderer still active"-case only. In your case, you seem to have a problem in onDrawFrame's try-block. Have a look at the actual exception and fix that. That should help.

JKumar

Hi ..I am not ommiting the call to display. Following is the code i am using-

public void onDrawFrame(GL10 gl) {
         
         try {
            
            
            if (!stop) {
               if (paused) {
                  Thread.sleep(500);
               } else {
                  if (resetFB) {
                     fb = new FrameBuffer(gl, w, h);
                     resetFB = false;
                  }

                  fb.clear();

                  //moveOpponent();
                  moveCharacter();
                  world.renderScene(fb);
                  world.draw(fb);
                  mTexturePack.blit(fb, imageId, 100, 100, true);
                  
                  fb.display();
               }
            } else {
               if (fb != null) {
                  fb.dispose();
                  fb = null;
                  
               }
            }
         } catch (Exception e)
         {
            Logger.log("Drawing thread terminated!", Logger.MESSAGE);
         }
      }

EgonOlsen

No, but you have a crash in that part of the code that you don't see because of the greedy catch-block. Add at least a e.printStackTrace() to the catch-block to see what actually happens there...

JKumar

Hi,

     Thanx for the suggestion and the problem was due to not packing the TexturePack object

I put this line and its working fine :)

mTexturePack.pack(true);