Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix locking problem with OpenGL on MacOSX and Linux #2647

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion ugs-platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<ugs.bundle.java.linux.x64.url>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</ugs.bundle.java.linux.x64.url>
<ugs.bundle.java.linux.arm.url>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</ugs.bundle.java.linux.arm.url>
<ugs.bundle.java.linux.aarch64.url>https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jre_aarch64_linux_hotspot_17.0.9_9.tar.gz</ugs.bundle.java.linux.aarch64.url>
<ugs.bundle.java.linux.aarch64.url>https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jre_aarch64_mac_hotspot_17.0.13_11.tar.gz</ugs.bundle.java.linux.aarch64.url>

<!-- Mac OS X signing identity - must match with a verified Apple developer certificate in the keychain -->
<ugs.codesign.identity>Developer ID Application</ugs.codesign.identity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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());
});
}
}