diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java index 183c2d660..506659690 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainLodControl.java @@ -156,6 +156,16 @@ public class TerrainLodControl extends AbstractControl { updateLOD(cameraLocations, lodCalculator); } } + + /** + * Call this when you remove the terrain or this control from the scene. + * It will clear up any threads it had. + */ + public void detachAndCleanUpControl() { + if (executor != null) + executor.shutdownNow(); + getSpatial().removeControl(this); + } // do all of the LOD calculations protected void updateLOD(List locations, LodCalculator lodCalculator) { diff --git a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java index 05cd0cabe..21f8435de 100644 --- a/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java +++ b/engine/src/test/jme3test/terrain/TerrainTestAdvanced.java @@ -220,8 +220,8 @@ public class TerrainTestAdvanced extends SimpleApplication { inputManager.addListener(actionListener, "triPlanar"); inputManager.addMapping("WardIso", new KeyTrigger(KeyInput.KEY_9)); inputManager.addListener(actionListener, "WardIso"); - inputManager.addMapping("Minnaert", new KeyTrigger(KeyInput.KEY_0)); - inputManager.addListener(actionListener, "Minnaert"); + inputManager.addMapping("DetachControl", new KeyTrigger(KeyInput.KEY_0)); + inputManager.addListener(actionListener, "DetachControl"); } private ActionListener actionListener = new ActionListener() { @@ -253,6 +253,15 @@ public class TerrainTestAdvanced extends SimpleApplication { matTerrain.setFloat("DiffuseMap_3_scale", rockScale); matTerrain.setFloat("DiffuseMap_4_scale", rockScale); } + } if (name.equals("DetachControl") && !pressed) { + TerrainLodControl control = terrain.getControl(TerrainLodControl.class); + if (control != null) + control.detachAndCleanUpControl(); + else { + control = new TerrainLodControl(terrain, cam); + terrain.addControl(control); + } + } } };