Skip to content

Commit 7b0fe87

Browse files
committed
#2562 Ensure all thread warden calls are asserts so can all be optised out
1 parent 87c94e6 commit 7b0fe87

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

jme3-core/src/main/java/com/jme3/app/SimpleApplication.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ protected BitmapFont loadGuiFont() {
198198
public void initialize() {
199199
super.initialize();
200200

201-
SceneGraphThreadWarden.setup(rootNode);
202-
SceneGraphThreadWarden.setup(guiNode);
201+
//noinspection AssertWithSideEffects
202+
assert SceneGraphThreadWarden.setup(rootNode);
203+
//noinspection AssertWithSideEffects
204+
assert SceneGraphThreadWarden.setup(guiNode);
203205

204206
// Several things rely on having this
205207
guiFont = loadGuiFont();
@@ -246,7 +248,8 @@ public void initialize() {
246248

247249
@Override
248250
public void stop(boolean waitFor) {
249-
SceneGraphThreadWarden.reset();
251+
//noinspection AssertWithSideEffects
252+
assert SceneGraphThreadWarden.reset();
250253
super.stop(waitFor);
251254
}
252255

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void setIgnoreTransform(boolean ignoreTransform) {
184184
*/
185185
@Override
186186
public void setLodLevel(int lod) {
187-
SceneGraphThreadWarden.assertOnCorrectThread(this);
187+
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
188188
if (mesh.getNumLodLevels() == 0) {
189189
throw new IllegalStateException("LOD levels are not set on this mesh");
190190
}
@@ -241,7 +241,7 @@ public int getTriangleCount() {
241241
* @throws IllegalArgumentException If mesh is null
242242
*/
243243
public void setMesh(Mesh mesh) {
244-
SceneGraphThreadWarden.assertOnCorrectThread(this);
244+
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
245245
if (mesh == null) {
246246
throw new IllegalArgumentException();
247247
}
@@ -272,7 +272,7 @@ public Mesh getMesh() {
272272
*/
273273
@Override
274274
public void setMaterial(Material material) {
275-
SceneGraphThreadWarden.assertOnCorrectThread(this);
275+
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
276276
this.material = material;
277277
nbSimultaneousGPUMorph = -1;
278278
if (isGrouped()) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ public class SceneGraphThreadWarden {
4343
* @param rootNode the root node of the scene graph. This is used to determine if a spatial is a child of the root node.
4444
* (Can add multiple "root" nodes, e.g. gui nodes or overlay nodes)
4545
*/
46-
public static void setup(Node rootNode){
46+
public static boolean setup(Node rootNode){
4747
if(checksDisabled()){
48-
return;
48+
return true;
4949
}
5050
Thread thisThread = Thread.currentThread();
5151
if(mainThread != null && mainThread != thisThread ){
5252
throw new IllegalStateException("The main thread has already been set to " + mainThread.getName() + " but now it's being set to " + Thread.currentThread().getName());
5353
}
5454
mainThread = thisThread;
5555
setTreeRestricted(rootNode);
56+
57+
return true; // return true so can be a "side effect" of an assert
5658
}
5759

5860
/**
@@ -116,10 +118,11 @@ public static boolean updateRequirement(Spatial spatial, Node newParent){
116118
return true; // return true so can be a "side effect" of an assert
117119
}
118120

119-
public static void reset(){
121+
public static boolean reset(){
120122
spatialsThatAreMainThreadReserved.clear();
121123
mainThread = null;
122124
THREAD_WARDEN_ENABLED = !Boolean.getBoolean("nothreadwarden");
125+
return true; // return true so can be a "side effect" of an assert
123126
}
124127

125128
private static boolean checksDisabled(){

0 commit comments

Comments
 (0)