diff options
author | Sven Gothel <[email protected]> | 2023-10-03 02:23:54 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-10-03 02:23:54 +0200 |
commit | 69549319e1d9ddf4d3903aa077f2c4cebb54195e (patch) | |
tree | 5792466d4391d73305b1b4245143b87f57494f74 /src | |
parent | e8c3c0382d58c8eabf4b96aa555683252c10d569 (diff) |
GraphUI Scene: Add custom one-time GLRunnable disposable action list, allowing to properly take-down user resources at dispose(GLAutoDrawable)
Used for UISceneDemo20 to stop and release SimpleSineSynth and its ALAudioSink.
The latter causes a bad exit (crash at OpenAL32.dll) on OpenJDK's Window Binary if not stopped!
Diffstat (limited to 'src')
-rw-r--r-- | src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java | 4 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Scene.java | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java index 56aeb861c..2942dd58a 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java @@ -765,6 +765,10 @@ public class UISceneDemo20 implements GLEventListener { } if( true ) { final SimpleSineSynth sineSound = new SimpleSineSynth(); + scene.addDisposeAction((final GLAutoDrawable glad) -> { + sineSound.stop(); + return true; + } ); sineSound.setFreq(200f); sineSound.setAmplitude(0.1f); final Button sineButton = new Button(renderModes, fontButtons, "lala", buttonRWidth, buttonRHeight); diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index 15ea27b14..cf3e16701 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -29,6 +29,7 @@ package com.jogamp.graph.ui; import java.io.File; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; @@ -522,11 +523,30 @@ public final class Scene implements Container, GLEventListener { for(int i=0; i<shapes.size(); i++) { shapes.get(i).destroy(gl, renderer); } + for(int i=0; i<disposeActions.size(); i++) { + try { + disposeActions.get(i).run(drawable); + } catch(final Throwable t) { + System.err.println("Scene.dispose: Caught Exception @ User Disposable["+i+"]: "+t.getMessage()); + t.printStackTrace(); + } + } shapes.clear(); cDrawable = null; + disposeActions.clear(); renderer.destroy(gl); screenshot.dispose(gl); } + private final List<GLRunnable> disposeActions = new ArrayList<GLRunnable>(); + /** + * Add a user one-time {@link GLRunnable} disposal action to an internal list, all invoked at {@Link #dispose(GLAutoDrawable)} + * where the list is cleared afterwards similar to all shapes. + * <p> + * This allows proper take-down of custom user resources at exit. + * </p> + * @param action the custom {@link GLRunnable} disposal action + */ + public void addDisposeAction(final GLRunnable action) { disposeActions.add(action); } /** * Attempt to pick a {@link Shape} using the window coordinates and contained {@ling Shape}'s {@link AABBox} {@link Shape#getBounds() bounds} |