Author Topic: NullPointerException when calling to renderScene  (Read 6214 times)

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
NullPointerException when calling to renderScene
« on: March 03, 2008, 06:18:52 pm »
Hi, I am getting a NullPointerException when calling to renderScene (buffer)

I am sure than neither the world nor the FrameBufer is null, so the problem must be a bug os something becausse it happens sometimes. not always.

I have tested the app on 2 machines. and this happens mostly on my P3 laptop with a GForce 2. on my P4 qith a fx 5600 almost never happens this.

this is the stackTrace:

Java version is: 1.6.0
-> support for BufferedImage
Version helper for 1.2+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Current mode:800 x 600 x 32 @60Hz
Driver is: nv4_disp/5.13.1.1533 on NVIDIA Corporation / GeForce2 MX/AGP/SSE
FBO not supported or disabled!
OpenGL renderer initialized (using 2 texture stages)
Software renderer disposed
Exception in thread "Thread-3" java.lang.NullPointerException
        at com.threed.jpct.Object3D.render(Unknown Source)
        at com.threed.jpct.World.renderScene(Unknown Source)
        at Flier_Match.FMCliente.video.RenderThread.mostrarImagen(RenderThread.j
ava:175)
        at Flier_Match.FMCliente.video.RenderThread.run(RenderThread.java:148)
Conexion establecida con: lrocha en el puerto: 8888
Recibiendo identificador del jugador y su nave
Identificador recibido: 2

Basicly this happens when I want to switch Worlds for rendering.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: NullPointerException when calling to renderScene
« Reply #1 on: March 04, 2008, 12:09:54 pm »
Looks like a threading issue to me. You are either switching video modes or are manipulating objects that jPCT is still rendering from outside the rendering thread. Keep in mind that jPCT isn't thread safe. When rendering in one thread, don't work with jPCT objects in another without synchronizing this.

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: NullPointerException when calling to renderScene
« Reply #2 on: March 04, 2008, 11:14:28 pm »
Yes, actually, I am using 2 threads, one for the rendering and another one for managing the events and the network iterarions as you suggested me some time ago. How can I sync them.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: NullPointerException when calling to renderScene
« Reply #3 on: March 05, 2008, 07:47:19 am »
Hard to tell without knowing what exactly you are doing in that event/network parts and if it needs synchronization, but basically, you shouldn't modify jPCT related objects like (the World, all Object3Ds...) from another thread then the rendering thread or you have to put a synchronized-block around these parts as well as around the rendering part and synchronize this with some generic sync-object (or whatever is appropriate in that situation). You may want to have a look at the advanced example in the download section. It has some client/server-code that does this. However, albeit its documented, it may take a time to get a grasp on it.

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: NullPointerException when calling to renderScene
« Reply #4 on: March 07, 2008, 01:07:07 am »
well, yes, I am affecting objects in the world. When a new player begans to play the server has to add it on the world and to remove when it quits from the game. I never have so any syncronizated threads before.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: NullPointerException when calling to renderScene
« Reply #5 on: March 07, 2008, 07:59:54 am »
You always have. The fact that it worked before is just a coincidence.

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: NullPointerException when calling to renderScene
« Reply #6 on: March 09, 2008, 01:38:42 am »
well, I guess I can add some checking changes methoids for my eventmanager class. On that way I can call this checking methods from the rendewrThread and then the affecting world methods will be on the renderThread. Anyway this happens just sometimes so I will do it and the end of my project.
Nada por ahora

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: NullPointerException when calling to renderScene
« Reply #7 on: March 22, 2008, 11:06:27 pm »
well, I did some changed and efectively the problem was that I was adding and building objects to the world on another thread while was rendering. No I added some checking methods for doing this things from inside the rendering Thread loop and worked well.
Nada por ahora