Interesting Exception (Resolved)

I have an interesting stack trace that I can not really explain. I think it might relate with the camera, just I can not figure out in what way. Maybe somebody already had this as well and knows the way out

20:50:54,379 INFO  [PlayerState] Add primary weapon "weapon.Shotgun" to player 0
Apr 26, 2021 8:51:16 PM handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ArrayIndexOutOfBoundsException: 5
	at com.jme3.util.ListSort.sort(
	at com.jme3.renderer.queue.GeometryList.sort(
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(
	at com.jme3.renderer.queue.RenderQueue.renderQueue(
	at com.jme3.renderer.RenderManager.renderViewPortQueues(
	at com.jme3.renderer.RenderManager.flushQueue(
	at com.jme3.renderer.RenderManager.renderViewPort(
	at com.jme3.renderer.RenderManager.render(
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(
1 Like

Which version of JME?

INFO: Running on jMonkeyEngine 3.3.0-stable
 * Branch: HEAD
 * Git Hash: 391e0dc
 * Build Date: 2020-03-30

Unfortunately I can not reproduce this easily with a simple one class example. I tried already. Somehow it must have to do with the camera.

    public void additionalUpdate(float tpf) {
        float zoom =  getLocation().z / (35 *35);

        float fw = width * zoom;
        float fh = height * zoom;
        getCamera().setFrustum(0, 100, -fw / 2, fw / 2, fh / 2, -fh / 2);

When I did this in the update it starts to happen at a certain point when my character walks and I change the zoom. But as I said I can not really say at which point as it does render the stuff just throws suddenly this exception.

1 Like

Could the application be modifying the scene graph from multiple threads?

1 Like

As far I know I have exactly one thread. I didn’t do any extra thread by my self. I have all states in the main like this

    public Main() {
        super(//new VideoRecorderAppState(new File("bubble.avi"), 1f, 50),
                new SteamState(),
                new ScreenshotAppState("", "bubble", 0),
                new FeatherState(),
                new EntityDataState(),
                new StatsAppState(),
                new TiledLevelSystem(),
                new TriggerSystem(),
                new DecaySystem(),
                new DelaySystem(),
                new PickupSystem(),
                new FuzeSystem(),
                new BombSystem(),
                new DestructionSystem(),
                new DamageSystem(),
                new DashingSystem(),
                new DeadOnTouchSystem(),
                new RemoveOnFallDownSystem(),
                new Dyn4jPhysicsSystem(),
                new NpcSystem(),
                new GdxAiSystem(),
                new FollowSystem(),
                new AutoAimingSystem(),
                new ModelViewState(),
                new CrazyLaughterState(),
                new FreeFallState(),
                new BeingBoredState(),
                new AnimationState(),
                new AimingState(),
                new SoundState(),
                new HudState(),
                //new HitViewState(),
                new CameraState(),
                new PlayerState());

It’s very weird. It happens when one of my character would get rendered. That is the closest point and only if I have parallel camera. I will look in that direction. But I’m sure neither dyn4j nor libgdx-ai behavior tree do have threading which could explain that.

1 Like

Here is the line where it happens:

…but this is internal book-keeping and assuming that the list/sort is consistent, the index should never be out of bounds.

So then we look at reasons that a sort might be inconsistent and one of the most common ways is because some geometries have bad sort semantics:
g1 > g2 and g2 > g1 sort of thing. Or usually what that boils down to is not(g1 > g2) and not(g2 > g1)

…which is significant because 99.9999999%(*) of the time this happens is because the position of one or more geometries is NaN. And usually that’s because some Quaternion became NaN.

So that’s a place to start looking. There are other watchdogs in the sort code that check for these cases (inconsistent sort order) but maybe the right confluence of events happened to pass that check and still cause an issue.

(*) Caveat on the 99.99999% is when an application extends Geometry in a way that affects the sorting behavior or implements their own broken Comparator. I’ve made assumptions that’s not the case here.


That’s right I did not extend the geometry. The quaternion NaN sounds like a place to look then. I’ll give it a try. Is it possible that it is somehow the blender to jm3 transformation went wrong? I will narrow it down and remove that character which starts to get rendered (because I walk toward it and it would then be visible) and most probably causes the issue.

1 Like

If a transform/position becomes NaN then it’s usually application code that does it.

…unless the model was ever able to be seen.

Easy enough to test by iterating the scene graph and dumping the positions and/or world bounding shapes.

It’s litterally a zoom, means going away from the scene. If I avoid that it works… and if I remove one of my states it works too even with the zoom. that looks very random to me. And I wonder where I messed it.
Also when I use 3.2 stable

Which state? Or is it any state? (That would be super strange.)

The other thing that could potentially cause this is the camera going NaN.

I’m not saying that something being NaN is for sure what is wrong but without looking you will never know.

It’s definitely super strange. I’m doing printf debugging. Camera could go NaN too. I’ll check that. If I remove certain amount of the 3D tiles this also helps. Such a pity I can not simply reproduce it it in a single class app :frowning:
It’s a state which checks how fast a falling dyn4j object is and then instantiate E models. Then switch to next level. then it happens. If I remove this sinple app it works. seems totally not correlated as those objects are gone.

If it were me, I might be tempted to override update() to call super.update() wrapped in a try catch for the exception… then use that as an opportunity to dump data bout the camera, all the different scene graphs, etc…

…but then I manage never to find myself in this situation in the first place somehow.

So it adds E models but then the objects are gone? Why does it instantiate them? Something about the above doesn’t parse for me.

Glad you don’t mange your self in this situation :smiley: seems I do. The E are 3 D models I place. and it looks likte the character does eject see my post in the monthly

The super update and catch try is maybe a good idea. I guess somewhere with dyn4j I messed it.
Thanks for all the pointers.

Nevertheless I don’t think you can help me anyway. I will close this topic. Something is wrong but I don’t yet see what it could be. Very small changes in code or tiles already avoid the exception.

Anyway thanks for your time.

Note: you have invested a lot of time into this thread and we’re all curious anyway.

…but you spent more time writing that post than it would take to add a try/catch and dump your transforms and see if this whole thread has been a waste of time so far or not. :slight_smile:

I guess a waste of time so far. But the pointers are helpful, I don’t think you can help more. I dumped and I didn’t find that NaN. But somehow I changed the position of my E where I use new Vec3d(pos.add(0, -1, 0)) changed it to Vec3d(pos.add(0.1f, -1, 0.1f) and boom it works. But those E’s are not there in the new loaded level as I have a decay of 500ms for that. And well I’m sure I messed it somewhere.

Ok anyway, I grateful for your help and no it took me not much time to write the posts. I use 10 finger system so I’m quite fast :smiley:

Anyway if I find something I will let you know. The not so fun thing is if I find that NaN object that would not help either it just would cement that I messed it. So this is pretty clear.

1 Like

One last note: I didn’t want a long thread I hoped for a a “ah this is a well known issue, just do this and that”. I wanted to stop early in the process as it was clear to me that nobody can really help. But it went out of hand and I let myself insult that only me manages to manover myself in this shit. Ok anyway frustrating is square and wish everybody good night. at least here it’s past midnight

80% of the reason I read this forum is for the really interesting strange problems. This one qualifies. Don’t beat yourself up too much.

You were today’s sudoku alternative. :slight_smile:


Btw. I probably keep that catch exception and write an error into the log but keep going. That might be even handy for future issues on other machines than mine. My laptop for example reacts more sensible to this exception. It looks to me that something behind the scene is bleeding.

Camera pos and rotation
CAM (48.854355, -24.015074, 260.0)(0.0, 1.0, -0.0, -4.371139E-8)

The only 3D tiles which looks a bit suspicious to me or which are clearly different to the rest are
XXX (90.0, -24.364214, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.364214, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.364214, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.364214, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.35751, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.35751, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.35751, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.35751, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.35751, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.43879, -24.144503, 5.373642E-17) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.43879, -24.144503, 5.373642E-17) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.43879, -24.144503, 5.373642E-17) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.43879, -24.144503, 5.373642E-17) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.331558, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.331558, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.331558, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.331558, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.005, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)
XXX (90.0, -24.005, 0.0) (0.0, 1.0, 0.0, 6.123234E-17)

So close to 0 but not 0 for the quaternion.

Does that maybe trigger your sudoku skills? :smiley:

I changed new Quatd() to new Quatd(0, 0, 0, 1) for initial positions with no rotation. And guess what, no exceptions. But that might just be luck and it happens somewhere else. I expected new Quatd() as a no rotation quaternion?