JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestAWTCloseX11DisplayBug565.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.acore;
2
3import jogamp.nativewindow.x11.X11Util;
4import org.junit.Assert;
5import org.junit.Test;
6import org.junit.FixMethodOrder;
7import org.junit.runners.MethodSorters;
8
9import com.jogamp.nativewindow.NativeWindowFactory;
10import com.jogamp.opengl.GLCapabilities;
11import com.jogamp.opengl.GLCapabilitiesImmutable;
12import com.jogamp.opengl.GLProfile;
13import com.jogamp.opengl.awt.GLCanvas;
14import java.awt.Frame;
15
16/**
17 * Tests the closing the device of GLCanvas in JOGL
18 */
19@FixMethodOrder(MethodSorters.NAME_ASCENDING)
21
22 @Test
23 public void testX11WindowMemoryLeak() throws Exception {
24 GLProfile.initSingleton(); // ensure shared resource runner is done
25 try {
26 for ( int j = 0; j < 10; j++ ) {
27 final int open0;
29 open0 = X11Util.getOpenDisplayConnectionNumber();
30 } else {
31 open0 = 0;
32 }
33
35 final Frame frame = new Frame( "AWT Resource X11 Leak - #" + j );
36
37 final GLCanvas glCanvas = new GLCanvas( caps );
38 frame.add( glCanvas );
39
40 try {
41 javax.swing.SwingUtilities.invokeAndWait( new Runnable() {
42 public void run() {
43 frame.setSize( 128, 128 );
44 frame.setVisible( true );
45 }
46 } );
47 }
48 catch ( final Throwable t ) {
49 t.printStackTrace();
50 Assert.fail(t.getMessage());
51 }
52 glCanvas.display();
53 try {
54 javax.swing.SwingUtilities.invokeAndWait( new Runnable() {
55 public void run() {
56 frame.setVisible( false );
57 frame.remove( glCanvas );
58 frame.dispose();
59 }
60 } );
61 }
62 catch ( final Throwable t ) {
63 t.printStackTrace();
64 Assert.fail(t.getMessage());
65 }
66
68 final int openD = X11Util.getOpenDisplayConnectionNumber() - open0;
69 if(openD>1) {
70 X11Util.dumpOpenDisplayConnections();
71 X11Util.dumpPendingDisplayConnections();
72 Assert.assertTrue("More than 1 new open display connections", false);
73 }
74 }
75 }
76 }
77 catch ( final Exception e ) {
78 e.printStackTrace();
79 Assert.fail(e.getMessage());
80 }
81 }
82
83
84 public static void main(final String args[]) {
85 org.junit.runner.JUnitCore.main(TestAWTCloseX11DisplayBug565.class.getName());
86 }
87
88}
89
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static final String TYPE_X11
X11 type, as retrieved with getNativeWindowType(boolean).
static String getNativeWindowType(final boolean useCustom)
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
Specifies an immutable set of OpenGL capabilities.