From 640761e7a1152d2777fd5785b2f7d2ada65493a9 Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Mon, 2 Dec 2024 14:54:22 +0100 Subject: [PATCH] Attempt to fix locking problem with OpenGL on MacOSX and Windows (#2647) --- ugs-platform/pom.xml | 2 +- .../visualizer/Visualizer2TopComponent.java | 18 ++++++++++- .../jogl/NewtVisualizationPanel.java | 31 ------------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/ugs-platform/pom.xml b/ugs-platform/pom.xml index dae6ecf82d..dc8a0d59f8 100644 --- a/ugs-platform/pom.xml +++ b/ugs-platform/pom.xml @@ -39,7 +39,7 @@ https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8.1%2B1/OpenJDK17U-jre_x64_linux_hotspot_17.0.8.1_1.tar.gz https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8.1%2B1/OpenJDK17U-jre_arm_linux_hotspot_17.0.8.1_1.tar.gz - https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jre_aarch64_linux_hotspot_17.0.9_9.tar.gz + https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jre_aarch64_mac_hotspot_17.0.13_11.tar.gz Developer ID Application 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 c85e08200b..7d42ce36d8 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 @@ -34,8 +34,12 @@ This file is part of Universal Gcode Sender (UGS). import javax.swing.BorderFactory; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import java.awt.BorderLayout; import java.awt.Color; +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static com.willwinder.ugs.nbp.lib.services.LocalizingService.lang; @@ -58,6 +62,7 @@ public final class Visualizer2TopComponent extends TopComponent { public final static String VisualizerWindowPath = LocalizingService.MENU_WINDOW; public final static String VisualizerActionId = "com.willwinder.ugs.nbm.visualizer.Visualizer2TopComponent"; public final static String VisualizerCategory = LocalizingService.CATEGORY_WINDOW; + private final ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "Visualizer2TopComponent GL Init")); public Visualizer2TopComponent() { setMinimumSize(new java.awt.Dimension(50, 50)); @@ -93,7 +98,18 @@ protected void componentOpened() { if (VisualizerOptions.getBooleanOption(VisualizerOptions.VISUALIZER_OPTION_LEGACY, false)) { borderedPanel.add(new VisualizationPanel(), BorderLayout.CENTER); } else { - borderedPanel.add(new NewtVisualizationPanel(), BorderLayout.CENTER); + WindowManager.getDefault().invokeWhenUIReady(() -> { + executor.execute(() -> { + try { + SwingUtilities.invokeAndWait(() -> { + borderedPanel.add(new NewtVisualizationPanel(), BorderLayout.CENTER); + borderedPanel.revalidate(); + }); + } catch (InterruptedException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + }); } add(borderedPanel, BorderLayout.CENTER); } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/jogl/NewtVisualizationPanel.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/jogl/NewtVisualizationPanel.java index 292a36540b..5366a966ba 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/jogl/NewtVisualizationPanel.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/jogl/NewtVisualizationPanel.java @@ -18,7 +18,6 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbm.visualizer.jogl; -import com.jogamp.common.util.locks.RecursiveLock; import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; @@ -129,11 +128,6 @@ private NewtCanvasAWT makeWindow() throws GLException { throw new IllegalArgumentException("Failed to access GcodeRenderer."); } - - RecursiveLock lock = glWindow.getLock(); - lock.lock(); - lock.unlock(); - FPSAnimator animator = new FPSAnimator(glWindow, 60); this.rih = new RendererInputHandler(renderer, animator, backend, 30, 60); @@ -153,36 +147,11 @@ private NewtCanvasAWT makeWindow() throws GLException { glWindow.addGLEventListener(renderer); p.setShallUseOffscreenLayer(true); - resize(); p.setBackground(Color.BLACK); p.setIgnoreRepaint(true); glWindow.setSurfaceScale(new float[]{ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE}); - - glWindow.addWindowListener(new com.jogamp.newt.event.WindowAdapter() { - @Override - public void windowResized(final com.jogamp.newt.event.WindowEvent e) { - resize(); - } - }); - - - animator.start(); return p; } - - - @Override - public void setBounds(int x, int y, int width, int height) { - super.setBounds(x, y, width, height); - resize(); - } - - private void resize() { - UPDATE_SIZE_SCHEDULER.execute(() -> { - glWindow.setPosition(0, 0); - glWindow.setSize(getWidth(), getHeight()); - }); - } }