2
0
Эх сурвалжийг харах

#2562 Ensure all thread warden calls are asserts so can all be optised out

Richard Tingle 2 сар өмнө
parent
commit
7b0fe87623

+ 6 - 3
jme3-core/src/main/java/com/jme3/app/SimpleApplication.java

@@ -198,8 +198,10 @@ public abstract class SimpleApplication extends LegacyApplication {
     public void initialize() {
         super.initialize();
 
-        SceneGraphThreadWarden.setup(rootNode);
-        SceneGraphThreadWarden.setup(guiNode);
+        //noinspection AssertWithSideEffects
+        assert SceneGraphThreadWarden.setup(rootNode);
+        //noinspection AssertWithSideEffects
+        assert SceneGraphThreadWarden.setup(guiNode);
 
         // Several things rely on having this
         guiFont = loadGuiFont();
@@ -246,7 +248,8 @@ public abstract class SimpleApplication extends LegacyApplication {
 
     @Override
     public void stop(boolean waitFor) {
-        SceneGraphThreadWarden.reset();
+        //noinspection AssertWithSideEffects
+        assert SceneGraphThreadWarden.reset();
         super.stop(waitFor);
     }
 

+ 3 - 3
jme3-core/src/main/java/com/jme3/scene/Geometry.java

@@ -184,7 +184,7 @@ public class Geometry extends Spatial {
      */
     @Override
     public void setLodLevel(int lod) {
-        SceneGraphThreadWarden.assertOnCorrectThread(this);
+        assert SceneGraphThreadWarden.assertOnCorrectThread(this);
         if (mesh.getNumLodLevels() == 0) {
             throw new IllegalStateException("LOD levels are not set on this mesh");
         }
@@ -241,7 +241,7 @@ public class Geometry extends Spatial {
      * @throws IllegalArgumentException If mesh is null
      */
     public void setMesh(Mesh mesh) {
-        SceneGraphThreadWarden.assertOnCorrectThread(this);
+        assert SceneGraphThreadWarden.assertOnCorrectThread(this);
         if (mesh == null) {
             throw new IllegalArgumentException();
         }
@@ -272,7 +272,7 @@ public class Geometry extends Spatial {
      */
     @Override
     public void setMaterial(Material material) {
-        SceneGraphThreadWarden.assertOnCorrectThread(this);
+        assert SceneGraphThreadWarden.assertOnCorrectThread(this);
         this.material = material;
         nbSimultaneousGPUMorph = -1;
         if (isGrouped()) {

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

@@ -43,9 +43,9 @@ public class SceneGraphThreadWarden {
      * @param rootNode the root node of the scene graph. This is used to determine if a spatial is a child of the root node.
      *                 (Can add multiple "root" nodes, e.g. gui nodes or overlay nodes)
      */
-    public static void setup(Node rootNode){
+    public static boolean setup(Node rootNode){
         if(checksDisabled()){
-            return;
+            return true;
         }
         Thread thisThread = Thread.currentThread();
         if(mainThread != null && mainThread != thisThread ){
@@ -53,6 +53,8 @@ public class SceneGraphThreadWarden {
         }
         mainThread = thisThread;
         setTreeRestricted(rootNode);
+
+        return true; // return true so can be a "side effect" of an assert
     }
 
     /**
@@ -116,10 +118,11 @@ public class SceneGraphThreadWarden {
         return true; // return true so can be a "side effect" of an assert
     }
 
-    public static void reset(){
+    public static boolean reset(){
         spatialsThatAreMainThreadReserved.clear();
         mainThread = null;
         THREAD_WARDEN_ENABLED = !Boolean.getBoolean("nothreadwarden");
+        return true; // return true so can be a "side effect" of an assert
     }
 
     private static boolean checksDisabled(){