Xith regression #4

In this case I am trying to remove a light from the scenegraph, surprisingly this ends up as an addLight down the stack trace causing me to use more lights than I should.

==>remove from bg org.xith3d.scenegraph.PointLight@188655e
Exception in thread “Thread-10” java.lang.ArrayIndexOutOfBoundsException: 8
at org.xith3d.render.shader.LightingShader.addLight(LightingShader.java:90)
at org.xith3d.render.prerender.AtomsCollector.collectGroupAtoms(AtomsCollector.java:258)
at org.xith3d.render.prerender.AtomsCollector.collectNodeAtoms(AtomsCollector.java:402)
at org.xith3d.render.prerender.AtomsCollector.collectAtoms(AtomsCollector.java:451)
at org.xith3d.render.ScenegraphModificationsManager.onChildRemovedFromGroup(ScenegraphModificationsManager.java:259)
at org.xith3d.scenegraph.GroupNode.removeChild(GroupNode.java:246)
at hawk.manager.LightManager.enableSet(LightManager.java:344)

Well, every time you add or remove a Light, something called “shaderstate” needs to be rebuilt for all affected Groups and Shapes. This means to readd all remaining Lights to the newly created shaderstates.
I’ll check the ArrayIndexOutOfBoundsException.

Marvin

Is that optimizable ?

The trouble is I have many lights but only 8 or less enabled at a time. The current processing is enabling more lights than Xith/Opengl support simultaneously. There is no reason why I cannot have 200 lights in a scenegraph if 8 or less are enabled

Yeah I don’t know how it should be handled, when more than eight light are enabled at the same time… maybe throw a self-explanative exception ?

I think it is more that the internals are enabling lights that I am not…if a light is not enabled then it shouldn’t BE enabled internally

Certainly. But not too easily. It certainly is a lower priorized task, isn’t it?

I guess you’re talking about added/removed Lights. But you should maybe consider enabling/disabling them. Then the shaderstates don’t need to be rebuilt.

Indeed.

Marvin

Fixed :).

Marvin

OK so that’s really not a big performance problem, just adds all your lights at the beginning of the scene and enable/disable them… maybe a transparent pool of lights could be used ?

Its back…When using latest SVN pull as of last night

Exception in thread “Thread-10” java.lang.ArrayIndexOutOfBoundsException: 8
at org.xith3d.render.shader.LightingShader.addLight(LightingShader.java:96)
at org.xith3d.render.prerender.AtomsCollector.collectGroupAtoms(AtomsCollector.java:248)
at org.xith3d.render.prerender.AtomsCollector.collectNodeAtoms(AtomsCollector.java:398)
at org.xith3d.render.prerender.AtomsCollector.collectAtoms(AtomsCollector.java:447)
at org.xith3d.render.ScenegraphModificationsManager.onChildRemovedFromGroup(ScenegraphModificationsManager.java:244)
at org.xith3d.scenegraph.GroupNode.removeChild(GroupNode.java:260)
at hawk.manager.LightManager.enableSet(LightManager.java:344)
at hawk.jcd.Xith3DFrame.runx(Xith3DFrame.java:746)
at hawk.jcd.Xith3DFrame.loopIteration(Xith3DFrame.java:616)
at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:882)
at java.lang.Thread.run(Unknown Source)

Just to set my situation…I have N rooms, each with one or more lights, potentialy giving 30-50 lights, less than 8 of which are in the scenegraph at any time… Based on user interaction I add or remove lights from the scenegraph. In the stack trace above I am removing a light from the scene, from within the RenderLoop. I cannot imagine why the light I am removing is being added…any thoughts appreciated

God dammed… :slight_smile:

As I said before, when a Light or Fog is removed, the shader state needs to be rebuilt. This is done by readding the Lights and Fogs. This is why Lights are added, when a Light actually is removed.

I’ve applied a fix, that should solve the problem. Please do revert, if it doesn’t.

Marvin

I looked briefly at the atom stuff and the test for lighting is checking for renderable not enabled. This is the stuff that always confuses me…is a not-enabled light renderable??? Seems like no to me but there are two separate states that describe whether a light is visible or not…YUCK!! I will try and set light as not-renederable when i set them not enabled.

This won’t do the trick! I’ve added a comment to AtomsCollector and committed. I’ll quote it here:

And a not-enabled Light is still renderable.

I hope this answers your question.

Marvin

Yee Heee found it.!!!

…at least for my situation. The code is adding my lights multiple times to the array that throws the exception. Since I don’t have dev rights could someone mod the code to determine if a Light is already in the array before attempting to add it and up the Light count.

at org.xith3d.render.shader.LightingShader.addLight(LightingShader.java:96)
at org.xith3d.render.prerender.AtomsCollector.collectGroupAtoms(AtomsCollector.java:248)
at org.xith3d.render.prerender.AtomsCollector.collectNodeAtoms(AtomsCollector.java:398)
at org.xith3d.render.prerender.AtomsCollector.collectAtoms(AtomsCollector.java:447)

Well, that was exactly, what I fixed yesterday ??? Don’t know, if you checked out after I posted it here.

Marvin

cool :stuck_out_tongue: