Skip to content

Commit 87c94e6

Browse files
committed
#2562 Log as well as exception (in case an executor service is being used where futures aren't promptly collected)
1 parent 2f7cf65 commit 87c94e6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

jme3-core/src/main/java/com/jme3/scene/threadwarden/SceneGraphThreadWarden.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.Collections;
77
import java.util.Set;
88
import java.util.WeakHashMap;
9+
import java.util.logging.Level;
10+
import java.util.logging.Logger;
911

1012
/**
1113
* Thread warden keeps track of mutations to the scene graph and ensures that they are only done on the main thread.
@@ -17,6 +19,8 @@
1719
*/
1820
public class SceneGraphThreadWarden {
1921

22+
private static final Logger logger = Logger.getLogger(SceneGraphThreadWarden.class.getName());
23+
2024
/**
2125
* If THREAD_WARDEN_ENABLED is true AND asserts are on the checks are made.
2226
* This parameter is here to allow asserts to run without thread warden checks (by setting this parameter to false)
@@ -129,7 +133,13 @@ public static boolean assertOnCorrectThread(Spatial spatial){
129133
}
130134
if(spatialsThatAreMainThreadReserved.contains(spatial)){
131135
if(Thread.currentThread() != mainThread){
132-
throw new IllegalThreadSceneGraphMutation("The spatial " + spatial + " was mutated on a thread other than the main thread, was mutated on " + Thread.currentThread().getName());
136+
// log as well as throw an exception because we are running in a thread, if we are in an executor service the exception
137+
// might not make itself known until `get` is called on the future (and JME might crash before that happens).
138+
String message = "The spatial " + spatial + " was mutated on a thread other than the main thread, was mutated on " + Thread.currentThread().getName();
139+
IllegalThreadSceneGraphMutation ex = new IllegalThreadSceneGraphMutation(message);
140+
logger.log(Level.WARNING, message, ex);
141+
142+
throw ex;
133143
}
134144
}
135145
return true; // return true so can be a "side effect" of an assert

0 commit comments

Comments
 (0)