diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java index 506f58cb66..ea9655d8d2 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java @@ -362,4 +362,8 @@ public void keyPressed(KeyEvent ke) { public void keyReleased(KeyEvent ke) { setFPS(LOW_FPS); } + + public void dispose() { + gcodeRenderer.dispose(); + } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/Visualizer2TopComponent.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/Visualizer2TopComponent.java index 560205b566..063e7e4c4b 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/Visualizer2TopComponent.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/Visualizer2TopComponent.java @@ -133,6 +133,7 @@ protected void componentClosed() { if (rih != null) { backend.removeUGSEventListener(rih); + rih.dispose(); } logger.log(Level.INFO, "Component closed, panel = " + panel); diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java index 801a0dcde6..c26d69f0f6 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java @@ -22,9 +22,16 @@ This file is part of Universal Gcode Sender (UGS). import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLEventListener; +import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW; +import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION; import com.jogamp.opengl.glu.GLU; import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; -import com.willwinder.ugs.nbm.visualizer.renderables.*; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BG; +import com.willwinder.ugs.nbm.visualizer.renderables.Grid; +import com.willwinder.ugs.nbm.visualizer.renderables.MachineBoundries; +import com.willwinder.ugs.nbm.visualizer.renderables.MouseOver; +import com.willwinder.ugs.nbm.visualizer.renderables.OrientationCube; +import com.willwinder.ugs.nbm.visualizer.renderables.Tool; import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; import com.willwinder.universalgcodesender.i18n.Localization; import com.willwinder.universalgcodesender.model.BackendAPI; @@ -39,7 +46,8 @@ This file is part of Universal Gcode Sender (UGS). import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; -import java.awt.*; +import java.awt.Font; +import java.awt.Point; import java.awt.event.InputEvent; import java.util.Collection; import java.util.Collections; @@ -47,10 +55,6 @@ This file is part of Universal Gcode Sender (UGS). import java.util.logging.Level; import java.util.logging.Logger; -import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW; -import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BG; - /** * 3D Canvas for GCode Visualizer * @@ -134,12 +138,7 @@ public GcodeRenderer() { setHorizontalTranslationVector(); objects = new CopyOnWriteArrayList<>(); - objects.add(new MachineBoundries(Localization.getString("platform.visualizer.renderable.machine-boundries"))); - objects.add(new Tool(Localization.getString("platform.visualizer.renderable.tool-location"))); - objects.add(new MouseOver(Localization.getString("platform.visualizer.renderable.mouse-indicator"))); - objects.add(new OrientationCube(0.5f, Localization.getString("platform.visualizer.renderable.orientation-cube"))); - objects.add(new Grid(Localization.getString("platform.visualizer.renderable.grid"))); - Collections.sort(objects); + initRenderables(); reloadPreferences(); listenForSettingsEvents(); @@ -199,7 +198,7 @@ public void setMachineCoordinate(Position p) { } } - final public void reloadPreferences() { + public final void reloadPreferences() { VisualizerOptions vo = new VisualizerOptions(); clearColor = vo.getOptionForKey(VISUALIZER_OPTION_BG).value; @@ -476,7 +475,24 @@ private void update() { */ @Override synchronized public void dispose(GLAutoDrawable drawable) { + dispose(); + } + + public void dispose() { logger.log(Level.INFO, "Disposing OpenGL context."); + getRenderables() + .forEach(this::removeRenderable); + initRenderables(); + } + + private void initRenderables() { + objects.clear(); + objects.add(new MachineBoundries(Localization.getString("platform.visualizer.renderable.machine-boundries"))); + objects.add(new Tool(Localization.getString("platform.visualizer.renderable.tool-location"))); + objects.add(new MouseOver(Localization.getString("platform.visualizer.renderable.mouse-indicator"))); + objects.add(new OrientationCube(0.5f, Localization.getString("platform.visualizer.renderable.orientation-cube"))); + objects.add(new Grid(Localization.getString("platform.visualizer.renderable.grid"))); + Collections.sort(objects); } private void setHorizontalTranslationVector() {