Re: freeze on macos Sonoma
Posted by SiboVG on Nov 18, 2023; 1:24am
URL: https://forum.jogamp.org/freeze-on-macos-Sonoma-tp4043021p4043142.html
Thank you for your patience @gouessej. I was finally able to create an SSCCE of the problem. When I run this Java Swing code, my program freezes:
```
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Rectangle;
public class Test3D {
public static void main(String[] args) {
JFrame frame = new JFrame();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
PhotoFrame pa = new PhotoFrame();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pa.setVisible(true);
}
});
}
private static class PhotoFrame extends JFrame {
public PhotoFrame() {
PhotoPanel photoPanel = new PhotoPanel();
setContentPane(photoPanel);
}
}
private static class PhotoPanel extends JPanel implements GLEventListener {
PhotoPanel() {
this.setLayout(new BorderLayout());
initGLCanvas();
}
private void initGLCanvas() {
Component canvas;
try {
final GLProfile glp = GLProfile.get(GLProfile.GL2);
final GLCapabilities caps = new GLCapabilities(glp);
canvas = new GLCanvas(caps); // NOTE: using GLJPanel did not work either
this.add(canvas, BorderLayout.CENTER);
} catch (Throwable t) {
this.add(new JLabel("Unable to load 3d Libraries: " + t.getMessage()));
}
}
@Override
public void paintImmediately(Rectangle r) { }
@Override
public void paintImmediately(int x, int y, int w, int h) { }
@Override
public void display(final GLAutoDrawable drawable) { }
@Override
public void init(final GLAutoDrawable drawable) { }
@Override
public void dispose(GLAutoDrawable glAutoDrawable) { }
@Override
public void reshape(GLAutoDrawable glAutoDrawable, int i, int i1, int i2, int i3) { }
}
}
```
However, when I change the order of execution in the main method by first setting PhotoFrame visible and then the normal frame (instead of vice versa), the application does not freeze :
```
public static void main(String[] args) {
PhotoFrame pa = new PhotoFrame();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pa.setVisible(true);
}
});
JFrame frame = new JFrame();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
}
```
Another example of a freeze scenario (same code, just different order):
```
public static void main(String[] args) {
JFrame frame = new JFrame();
PhotoFrame pa = new PhotoFrame();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pa.setVisible(true);
}
});
}
```
In the above code, when switching the order of the two runnables, the application does not freezes. Also when I comment out either one of the runnables, the application does not freezes. Placing the two `setVisible` calls in the same invokeLater call has the same effect: the application only freezes when `frame.setVisible(true);` is called before `pa.setVisible(true);`.