ShadowHelper Bug?

Started by AGP, November 06, 2014, 07:02:15 PM

Previous topic - Next topic

AGP

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();

QuoteException 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)

EgonOlsen

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...

EgonOlsen

No, wait...it's not. It's a problem with objects that have no additional color. I'll provide a fixed version...

EgonOlsen

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

AGP

I appreciate the effort, but now, the message changed to:
QuoteException 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)

EgonOlsen

But THAT is a multi-threading issue. Someone modifies the collection of objects while preparing for shadow rendering, and it's certainly not me... ;)

AGP

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.

EgonOlsen

Anyway, the setAdditionalColor() method now can deal with null values, which is a good thing... ;)