www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on November 06, 2014, 07:02:15 pm

Title: ShadowHelper Bug?
Post by: AGP 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)
Title: Re: ShadowHelper Bug?
Post by: EgonOlsen 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...
Title: Re: ShadowHelper Bug?
Post by: EgonOlsen 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...
Title: Re: ShadowHelper Bug?
Post by: EgonOlsen on November 06, 2014, 08:23:40 pm
This should fix it: http://jpct.de/download/beta/jpct.jar (http://jpct.de/download/beta/jpct.jar)

I wonder why this hasn't been a problem earlier...the code is years old... :o
Title: Re: ShadowHelper Bug?
Post by: AGP 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)
Title: Re: ShadowHelper Bug?
Post by: EgonOlsen 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... ;)
Title: Re: ShadowHelper Bug?
Post by: AGP 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.
Title: Re: ShadowHelper Bug?
Post by: EgonOlsen on November 06, 2014, 08:54:52 pm
Anyway, the setAdditionalColor() method now can deal with null values, which is a good thing... ;)