Author Topic: NPE, what is null here?  (Read 5428 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
NPE, what is null here?
« on: December 17, 2010, 03:44:15 am »
this sometimes happes when i press home button. not sure what is null here?

Code: [Select]
java.lang.NullPointerException
  at com.threed.jpct.GLRenderer.blit(GLRenderer.java:1252)
  at com.threed.jpct.GLRenderer.execute(GLRenderer.java:1668)
  at com.threed.jpct.FrameBuffer.blit(FrameBuffer.java:594)
  at raft.glgui.android.TexturePack.blit(TexturePack.java:259)
 ..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #1 on: December 17, 2010, 07:42:13 am »
Maybe the texture to blit? I'm not sure if i'm looking at the latest sources right now...i'll look at this in more detail when i get home.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: NPE, what is null here?
« Reply #2 on: December 17, 2010, 02:37:17 pm »
i dont think so. once packed, texture is never nullified in TexturePack.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #3 on: December 17, 2010, 06:29:05 pm »
But it has to. This is the code at that line:

Code: [Select]
float h = (float) t.getHeight();

where t is the texture that is directly feed into the method from the FrameBuffer's blit-method. However, some dispose or remove-methods clear that reference when executed in another thread, especially when finalizing the framebuffer. Might be that the old framebuffer get's finalized and that triggers the clear process...i'll see what to do to fix this...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: NPE, what is null here?
« Reply #4 on: December 17, 2010, 06:37:25 pm »
mm, there is a call to FrameBuffer.freeMemory() in my onPause() and onStop() methods, that may be the cause (they are executed in gui thread)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #5 on: December 17, 2010, 08:14:49 pm »
Might be, but my clear logic was flawed anyway. It might be better now, please give the new jar a try: http://www.jpct.net/jpct-ae/download/alpha/jpct_ae.jar

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: NPE, what is null here?
« Reply #6 on: December 17, 2010, 08:27:12 pm »
after a few tries, i've got another NPE:

Code: [Select]
java.lang.NullPointerException
  at com.threed.jpct.Interact2D.reproject2D3DBlit(Interact2D.java:269)
  at com.threed.jpct.GLRenderer.blit(GLRenderer.java:1312)
  at com.threed.jpct.GLRenderer.execute(GLRenderer.java:1668)
  at com.threed.jpct.FrameBuffer.blit(FrameBuffer.java:594)
  at raft.glgui.android.TexturePack.blit(TexturePack.java:259)
        ...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #7 on: December 17, 2010, 08:29:54 pm »
That can only happen, if the FrameBuffer given to that method is null.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: NPE, what is null here?
« Reply #8 on: December 17, 2010, 08:49:05 pm »
are you sure? i've put a try catch around that block, catch NPE and print buffer, it seems not null ???

btw, other NPE seems to be gone ;D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #9 on: December 17, 2010, 08:55:27 pm »
Yes, i'm sure...but i wasn't aware that i'm calling this method... ;D The problem seems to be, that the blitting happens in parallel with your freeMemory()-call. I can't really handle this 100%. I've uploaded a new jar that tries to, but there's still room for failure. Can you synchronize the freeMemory call somehow?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: NPE, what is null here?
« Reply #10 on: December 17, 2010, 09:02:21 pm »
i dont get it. freeMemory() call cannot set my FrameBuffer to null, which you say certainly is null.

i'm trying to avoid synchronized blocks but i can try some othe kind of synchronization.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #11 on: December 17, 2010, 09:05:34 pm »
It's a bit complicated. AE uses some static Object arrays to store data, like the the data that is passed down to the renderer for blitting. These buffers need some cleanup from time to time or otherwise. they'll keep references to unused objects for ever. freeMemory() removes references to the frame buffer from these buffers but if the renderer tries to blit that thing on this moment, it get null instead of the (now invalid) buffer.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: NPE, what is null here?
« Reply #12 on: December 17, 2010, 09:15:06 pm »
i see. so i dont pass a null buffer but an invalidate buffer.

btw, i see some "All texture data unloaded from gpu!" logs, is this done at freeMemory() ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: NPE, what is null here?
« Reply #13 on: December 17, 2010, 09:17:21 pm »
Yes, it is.