Skip to content

Commit 2a0a746

Browse files
committed
#2562 IAdd tes for disabled thread checks
1 parent b0b2477 commit 2a0a746

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static boolean updateRequirement(Spatial spatial, Node newParent){
115115
public static void reset(){
116116
spatialsThatAreMainThreadReserved.clear();
117117
mainThread = null;
118+
THREAD_WARDEN_ENABLED = !Boolean.getBoolean("nothreadwarden");
118119
}
119120

120121
private static boolean checksDisabled(){

jme3-core/src/test/java/com/jme3/scene/threadwarden/SceneGraphThreadWardenTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.concurrent.Future;
1313
import java.util.concurrent.ThreadFactory;
1414

15-
import static org.junit.Assert.assertFalse;
1615
import static org.junit.Assert.assertTrue;
1716
import static org.junit.Assert.fail;
1817

@@ -266,6 +265,34 @@ public void testRemovingAChildFromTheRootNodeAlsoUnrestrictsTheGrandChild() thro
266265
legalMutationFuture.get();
267266
}
268267

268+
/**
269+
* Test that an otherwise illegal scene graph mutation won't throw an exception
270+
* if the checks have been disabled by calling disableChecks().
271+
*/
272+
@Test
273+
public void testDisableChecksAllowsIllegalMutation() throws ExecutionException, InterruptedException {
274+
Node rootNode = new Node("root");
275+
SceneGraphThreadWarden.setup(rootNode);
276+
277+
// Create a child node and attach it to the root node
278+
Node child = new Node("child");
279+
rootNode.attachChild(child);
280+
281+
// Disable the thread warden checks
282+
SceneGraphThreadWarden.disableChecks();
283+
284+
// Try to make a change to the child on a non-main thread
285+
// This would normally be illegal, but should succeed because checks are disabled
286+
Future<Void> mutationFuture = executorService.submit(() -> {
287+
Node grandchild = new Node("grandchild");
288+
child.attachChild(grandchild);
289+
return null;
290+
});
291+
292+
// This should complete without exceptions
293+
mutationFuture.get();
294+
}
295+
269296

270297

271298
/**

0 commit comments

Comments
 (0)