Uncaught exception with updateLogicalState()


From time to time, I got this exception on server side while in combat. I did not manage to found a way to catch it and/or debug :frowning:

Is someone known something about this issue ?
Thank you, I’m really stuck :c

[java]juin 14, 2014 6:37:24 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[Headless Application Thread,5,main]
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
at com.jme3.system.NullContext.run(NullContext.java:130)
at java.lang.Thread.run(Thread.java:722)[/java]

If it happens only sometimes it might be a concurrency issue, like you remove a control on another thread. You could add an assertion to the respective methods of Spatial to check if thats the case. I take it you don’t have any special extensions or modify the Nodes control list manually and always use Spatial.addControl and removeControl.

@normen said: You could add an assertion to the respective methods of Spatial to check if thats the case.

I’m afraid I don’t know how to do that. Could you please explain a bit more what to do ?

Just add something like

static Thread thread;
if(thread == null){
thread = Thread.currentThread();
else if(Thread.currentThread!=thread){
throw new IllegalStateException(“thread changed!”);

to the Spatial.addControl and .removeControl methods.

Hm, actually best make the Thread variable static so that it works even if one control always gets removed/added by the wrong thread, edited the example

Is it possible that this exception was raised about some Spatial added / removed from node ? Even if i used app.enqueue(Callable) ?

Because I’ve searched for some control add/remove in separated thread and found nothing…
You said that it might be a conccurency issue, so I’ll try to change the logic and put some loop in main thread instead of a timer thread.

Thank you for your quick support & hints :slight_smile:

Actually, I think the only way you can get this error is if you are iterating the children on some other thread. The scene graph is not thread safe at all… this goes for reading or writing.

Many people think that it is ok to read unprotected resources from separate threads because “I’m only reading”. But actually, this is never true. Even a shared int can give you issues (for example, one thread could change the int and another thread may never see that change because the value was cached locally). But this is especially true for something like JME’s scene graph because it internally does some things that rely on being single threaded for performance.

In this case, you’re iterating over the children from a separate thread and your main thread happened to catch it in the middle of creating its internal cached child array. Essentially, an entry in the child array is null when this exception happens and that can normally never be the case unless you catch it in the middle of generating this array on another thread.

Thank you @pspeed for your explanation. I’ve change some code blocks and I have to test the game now, in real conditions.
My lack of skills with this kind of stuff prevents me of being 100% sure.

We test an internal release of CHAOS 2.6.2 this weekend, I’ll post here some feedback :slight_smile: