Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jme3-core/src/main/java/com/jme3/app/SimpleApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial.CullHint;
import com.jme3.scene.threadwarden.SceneGraphThreadWarden;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext.Type;
import com.jme3.system.JmeSystem;
Expand Down Expand Up @@ -197,6 +198,11 @@ protected BitmapFont loadGuiFont() {
public void initialize() {
super.initialize();

//noinspection AssertWithSideEffects
assert SceneGraphThreadWarden.setup(rootNode);
//noinspection AssertWithSideEffects
assert SceneGraphThreadWarden.setup(guiNode);

// Several things rely on having this
guiFont = loadGuiFont();

Expand Down Expand Up @@ -240,6 +246,13 @@ public void initialize() {
simpleInitApp();
}

@Override
public void stop(boolean waitFor) {
//noinspection AssertWithSideEffects
assert SceneGraphThreadWarden.reset();
super.stop(waitFor);
}

@Override
public void update() {
if (prof != null) {
Expand Down
4 changes: 4 additions & 0 deletions jme3-core/src/main/java/com/jme3/scene/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.jme3.renderer.Camera;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.mesh.MorphTarget;
import com.jme3.scene.threadwarden.SceneGraphThreadWarden;
import com.jme3.util.TempVars;
import com.jme3.util.clone.Cloner;
import com.jme3.util.clone.IdentityCloneFunction;
Expand Down Expand Up @@ -183,6 +184,7 @@ public void setIgnoreTransform(boolean ignoreTransform) {
*/
@Override
public void setLodLevel(int lod) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (mesh.getNumLodLevels() == 0) {
throw new IllegalStateException("LOD levels are not set on this mesh");
}
Expand Down Expand Up @@ -239,6 +241,7 @@ public int getTriangleCount() {
* @throws IllegalArgumentException If mesh is null
*/
public void setMesh(Mesh mesh) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (mesh == null) {
throw new IllegalArgumentException();
}
Expand Down Expand Up @@ -269,6 +272,7 @@ public Mesh getMesh() {
*/
@Override
public void setMaterial(Material material) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
this.material = material;
nbSimultaneousGPUMorph = -1;
if (isGrouped()) {
Expand Down
9 changes: 9 additions & 0 deletions jme3-core/src/main/java/com/jme3/scene/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.material.Material;
import com.jme3.scene.threadwarden.SceneGraphThreadWarden;
import com.jme3.util.SafeArrayList;
import com.jme3.util.clone.Cloner;
import java.io.IOException;
Expand Down Expand Up @@ -201,6 +202,7 @@ private void addUpdateChildren(SafeArrayList<Spatial> results) {
* that would change state.
*/
void invalidateUpdateList() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
updateListValid = false;
if (parent != null) {
parent.invalidateUpdateList();
Expand Down Expand Up @@ -344,6 +346,7 @@ public int attachChild(Spatial child) {
* @throws IllegalArgumentException if child is null or this
*/
public int attachChildAt(Spatial child, int index) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (child == null) {
throw new IllegalArgumentException("child cannot be null");
}
Expand Down Expand Up @@ -428,6 +431,7 @@ public int detachChildNamed(String childName) {
* @return the child at the supplied index.
*/
public Spatial detachChildAt(int index) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
Spatial child = children.remove(index);
if (child != null) {
child.setParent(null);
Expand Down Expand Up @@ -455,6 +459,7 @@ public Spatial detachChildAt(int index) {
* node.
*/
public void detachAllChildren() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
// Note: this could be a bit more efficient if it delegated
// to a private method that avoided setBoundRefresh(), etc.
// for every child and instead did one in here at the end.
Expand Down Expand Up @@ -483,6 +488,7 @@ public int getChildIndex(Spatial sp) {
* @param index2 The index of the second child to swap
*/
public void swapChildren(int index1, int index2) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
Spatial c2 = children.get(index2);
Spatial c1 = children.remove(index1);
children.add(index1, c2);
Expand Down Expand Up @@ -562,6 +568,7 @@ public List<Spatial> getChildren() {

@Override
public void setMaterial(Material mat) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
for (int i = 0; i < children.size(); i++) {
children.get(i).setMaterial(mat);
}
Expand Down Expand Up @@ -778,6 +785,7 @@ public void read(JmeImporter importer) throws IOException {

@Override
public void setModelBound(BoundingVolume modelBound) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (children != null) {
for (Spatial child : children.getArray()) {
child.setModelBound(modelBound != null ? modelBound.clone(null) : null);
Expand All @@ -787,6 +795,7 @@ public void setModelBound(BoundingVolume modelBound) {

@Override
public void updateModelBound() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (children != null) {
for (Spatial child : children.getArray()) {
child.updateModelBound();
Expand Down
16 changes: 15 additions & 1 deletion jme3-core/src/main/java/com/jme3/scene/Spatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.control.Control;
import com.jme3.scene.threadwarden.SceneGraphThreadWarden;
import com.jme3.util.SafeArrayList;
import com.jme3.util.TempVars;
import com.jme3.util.clone.Cloner;
Expand Down Expand Up @@ -278,11 +279,13 @@ protected void setRequiresUpdates(boolean f) {
* a refresh is required.
*/
protected void setTransformRefresh() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
refreshFlags |= RF_TRANSFORM;
setBoundRefresh();
}

protected void setLightListRefresh() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
refreshFlags |= RF_LIGHTLIST;
// Make sure next updateGeometricState() visits this branch
// to update lights.
Expand All @@ -299,6 +302,7 @@ protected void setLightListRefresh() {
}

protected void setMatParamOverrideRefresh() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
refreshFlags |= RF_MATPARAM_OVERRIDE;
Spatial p = parent;
while (p != null) {
Expand All @@ -316,6 +320,7 @@ protected void setMatParamOverrideRefresh() {
* a refresh is required.
*/
protected void setBoundRefresh() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
refreshFlags |= RF_BOUND;

Spatial p = parent;
Expand Down Expand Up @@ -364,7 +369,8 @@ public boolean checkCulling(Camera cam) {
throw new IllegalStateException("Scene graph is not properly updated for rendering.\n"
+ "State was changed after rootNode.updateGeometricState() call. \n"
+ "Make sure you do not modify the scene from another thread!\n"
+ "Problem spatial name: " + getName());
+ "Problem spatial name: " + getName() + "\n" +
SceneGraphThreadWarden.getTurnOnAssertsPrompt());
}

CullHint cm = getCullHint();
Expand Down Expand Up @@ -612,6 +618,7 @@ protected void updateMatParamOverrides() {
* @see MatParamOverride
*/
public void addMatParamOverride(MatParamOverride override) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (override == null) {
throw new IllegalArgumentException("override cannot be null");
}
Expand All @@ -626,6 +633,7 @@ public void addMatParamOverride(MatParamOverride override) {
* @see MatParamOverride
*/
public void removeMatParamOverride(MatParamOverride override) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (localOverrides.remove(override)) {
setMatParamOverrideRefresh();
}
Expand All @@ -637,6 +645,7 @@ public void removeMatParamOverride(MatParamOverride override) {
* @see #addMatParamOverride(com.jme3.material.MatParamOverride)
*/
public void clearMatParamOverrides() {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
if (!localOverrides.isEmpty()) {
setMatParamOverrideRefresh();
}
Expand Down Expand Up @@ -772,6 +781,7 @@ public void runControlRender(RenderManager rm, ViewPort vp) {
* @see Spatial#removeControl(java.lang.Class)
*/
public void addControl(Control control) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
boolean before = requiresUpdates();
controls.add(control);
control.setSpatial(this);
Expand Down Expand Up @@ -823,6 +833,7 @@ public void addControlAt(int index, Control control) {
* @see Spatial#addControl(com.jme3.scene.control.Control)
*/
public void removeControl(Class<? extends Control> controlType) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
boolean before = requiresUpdates();
for (int i = 0; i < controls.size(); i++) {
if (controlType.isAssignableFrom(controls.get(i).getClass())) {
Expand Down Expand Up @@ -850,6 +861,7 @@ public void removeControl(Class<? extends Control> controlType) {
* @see Spatial#addControl(com.jme3.scene.control.Control)
*/
public boolean removeControl(Control control) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
boolean before = requiresUpdates();
boolean result = controls.remove(control);
if (result) {
Expand Down Expand Up @@ -1005,6 +1017,7 @@ public Node getParent() {
* the parent of this node.
*/
protected void setParent(Node parent) {
assert SceneGraphThreadWarden.updateRequirement(this, parent);
this.parent = parent;
}

Expand Down Expand Up @@ -1369,6 +1382,7 @@ public RenderQueue.ShadowMode getShadowMode() {
* @param lod The lod level to set.
*/
public void setLodLevel(int lod) {
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jme3.scene.threadwarden;

public class IllegalThreadSceneGraphMutation extends IllegalStateException{
public IllegalThreadSceneGraphMutation(String message){
super(message);
}
}
Loading
Loading