Author Topic: ShadowHelper Bug?  (Read 955 times)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
ShadowHelper Bug?
« on: November 06, 2014, 07:02:15 pm »
I'm making a zombie-shooting game about which I'm very excited. I've just run into a problem, though: when I enable shadows and I press fire my shotgun, the following message immediately appears. The two casters so far are the hero and his shotgun. The only receiver is the ground. But when you fire, a bullet (which is a sphere as returned by Primitives.getSphere(...)) is spawned. Note: line 583 is sh.drawScene();

Quote
Exception in thread "main" java.lang.NullPointerException
        at com.threed.jpct.Object3D.setAdditionalColor(Object3D.java:2632)
        at com.threed.jpct.util.ShadowHelper.drawScene(ShadowHelper.java:401)
        at com.threed.jpct.util.ShadowHelper.drawScene(ShadowHelper.java:342)
        at RPG3D.doShadows(RPG3D.java:583)
        at RPG3D.draw(RPG3D.java:563)
        at RPG3D.gameLoop(RPG3D.java:522)
        at RPG3D.<init>(RPG3D.java:168)
        at RPG3D.main(RPG3D.java:928)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper Bug?
« Reply #1 on: November 06, 2014, 08:10:33 pm »
As in 99.x% of these cases, the reason is most likely that adding objects (the bullet in this case) to the world while rendering (i.e. in another thread than the rendering thread) isn't a good idea...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper Bug?
« Reply #2 on: November 06, 2014, 08:15:47 pm »
No, wait...it's not. It's a problem with objects that have no additional color. I'll provide a fixed version...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper Bug?
« Reply #3 on: November 06, 2014, 08:23:40 pm »
This should fix it: http://jpct.de/download/beta/jpct.jar

I wonder why this hasn't been a problem earlier...the code is years old... :o

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: ShadowHelper Bug?
« Reply #4 on: November 06, 2014, 08:31:17 pm »
I appreciate the effort, but now, the message changed to:
Quote
Exception in thread "main" java.util.ConcurrentModificationException
        at com.threed.jpct.Object3DList$1.hasMoreElements(Object3DList.java:95)
        at com.threed.jpct.util.ShadowHelper.drawScene(ShadowHelper.java:367)
        at com.threed.jpct.util.ShadowHelper.drawScene(ShadowHelper.java:342)
        at RPG3D.doShadows(RPG3D.java:583)
        at RPG3D.draw(RPG3D.java:563)
        at RPG3D.gameLoop(RPG3D.java:522)
        at RPG3D.<init>(RPG3D.java:168)
        at RPG3D.main(RPG3D.java:928)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper Bug?
« Reply #5 on: November 06, 2014, 08:33:34 pm »
But THAT is a multi-threading issue. Someone modifies the collection of objects while preparing for shadow rendering, and it's certainly not me... ;)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: ShadowHelper Bug?
« Reply #6 on: November 06, 2014, 08:41:17 pm »
Ah, so it was both issues. I moved the bullet creation into the loop and fired ten times in a row successfully. Thanks a lot.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: ShadowHelper Bug?
« Reply #7 on: November 06, 2014, 08:54:52 pm »
Anyway, the setAdditionalColor() method now can deal with null values, which is a good thing... ;)