Author Topic: Blitting Image using TexturePack  (Read 5745 times)

Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Blitting Image using TexturePack
« on: October 22, 2010, 01:35:25 pm »
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 ?
                  
         

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Blitting Image using TexturePack
« Reply #1 on: October 22, 2010, 01:40:13 pm »
unless you arent creating TexturePack every frame, this has nothing to do with TexturePack.
what is the size (dimensions) of your image?

Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Re: Blitting Image using TexturePack
« Reply #2 on: October 22, 2010, 01:44:21 pm »
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!

Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Re: Blitting Image using TexturePack
« Reply #3 on: October 22, 2010, 01:46:05 pm »
W =  72 pix
H = 63 pix

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Blitting Image using TexturePack
« Reply #4 on: October 22, 2010, 01:48:58 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blitting Image using TexturePack
« Reply #5 on: October 22, 2010, 01:50:19 pm »
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.

Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Re: Blitting Image using TexturePack
« Reply #6 on: October 22, 2010, 02:09:15 pm »
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);
         }
      }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Blitting Image using TexturePack
« Reply #7 on: October 22, 2010, 02:17:12 pm »
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...

Offline JKumar

  • byte
  • *
  • Posts: 33
    • View Profile
Re: Blitting Image using TexturePack
« Reply #8 on: October 22, 2010, 03:42:03 pm »
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);