JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestNEWTCloseX11DisplayBug565.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.acore;
2
3import jogamp.nativewindow.x11.X11Util;
4
5import org.junit.Assert;
6import org.junit.Test;
7import org.junit.FixMethodOrder;
8import org.junit.runners.MethodSorters;
9
10import com.jogamp.newt.opengl.GLWindow;
11
12import com.jogamp.nativewindow.NativeWindowFactory;
13import com.jogamp.opengl.DefaultGLCapabilitiesChooser;
14import com.jogamp.opengl.GLAutoDrawable;
15import com.jogamp.opengl.GLCapabilities;
16import com.jogamp.opengl.GLCapabilitiesImmutable;
17import com.jogamp.opengl.GLDrawableFactory;
18import com.jogamp.opengl.GLOffscreenAutoDrawable;
19import com.jogamp.opengl.GLProfile;
20
21/**
22 * Tests the closing the device of GLWindow and off-screen GLAutoDrawable using FBO and PBuffer in JOGL
23 */
24@FixMethodOrder(MethodSorters.NAME_ASCENDING)
26
27 @Test
28 public void test01X11WindowMemoryLeak() throws Exception {
29 GLProfile.initSingleton(); // ensure shared resource runner is done
30 try {
31 for ( int j = 0; j < 10; j++ ) {
32 final int open0;
34 open0 = X11Util.getOpenDisplayConnectionNumber();
35 } else {
36 open0 = 0;
37 }
38
40
41 final GLWindow window = GLWindow.create(caps);
42 window.setTitle("NEWT Resource X11 Leak - #" + j );
43 window.setSize( 128, 128 );
44 window.setVisible(true);
45 window.display();
46 window.setVisible(false);
47 window.destroy();
48
50 final int openD = X11Util.getOpenDisplayConnectionNumber() - open0;
51 if( openD > 0) {
52 X11Util.dumpOpenDisplayConnections();
53 X11Util.dumpPendingDisplayConnections();
54 Assert.assertEquals("New display connection didn't close", 0, openD);
55 }
56 }
57 }
58 }
59 catch ( final Exception e ) {
60 e.printStackTrace();
61 Assert.fail(e.getMessage());
62 }
63 }
64
65
66 @Test
67 public void test02X11WindowMemoryLeakPBufferAutoDrawable() throws Exception {
68 GLProfile.initSingleton(); // ensure shared resource runner is done
69 try {
70 for ( int j = 0; j < 10; j++ ) {
71 final int open0;
73 open0 = X11Util.getOpenDisplayConnectionNumber();
74 } else {
75 open0 = 0;
76 }
77 final GLProfile glp = GLProfile.getDefault( );
78 final GLCapabilities caps = new GLCapabilities( glp );
79 caps.setPBuffer(true);
80 final GLAutoDrawable buffer = GLDrawableFactory.getFactory( glp ).createOffscreenAutoDrawable(null, caps, null, 256, 256);
81 buffer.display();
82 buffer.destroy();
83
85 final int openD = X11Util.getOpenDisplayConnectionNumber() - open0;
86 if(openD > 0) {
87 X11Util.dumpOpenDisplayConnections();
88 X11Util.dumpPendingDisplayConnections();
89 Assert.assertEquals("New display connection didn't close", 0, openD);
90 }
91 }
92 }
93 }
94 catch ( final Exception e ) {
95 e.printStackTrace();
96 Assert.fail(e.getMessage());
97 }
98 }
99
100 @Test
101 public void test03X11WindowMemoryLeakFBOAutoDrawable() throws Exception {
102 GLProfile.initSingleton(); // ensure shared resource runner is done
103 try {
104 for ( int j = 0; j < 10; j++ ) {
105 final int open0;
107 open0 = X11Util.getOpenDisplayConnectionNumber();
108 } else {
109 open0 = 0;
110 }
111 final GLProfile glp = GLProfile.getDefault( );
112 final GLCapabilitiesImmutable caps = new GLCapabilities( glp );
113
114
116 null, caps, new DefaultGLCapabilitiesChooser(), 256, 256);
117 buffer.display();
118 buffer.destroy();
119
121 final int openD = X11Util.getOpenDisplayConnectionNumber() - open0;
122 if(openD > 0) {
123 X11Util.dumpOpenDisplayConnections();
124 X11Util.dumpPendingDisplayConnections();
125 Assert.assertEquals("New display connection didn't close", 0, openD);
126 }
127 }
128 }
129 }
130 catch ( final Exception e ) {
131 e.printStackTrace();
132 Assert.fail(e.getMessage());
133 }
134 }
135
136 public static void main(final String args[]) {
137 org.junit.runner.JUnitCore.main(TestNEWTCloseX11DisplayBug565.class.getName());
138 }
139
140}
141
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)
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
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
Tests the closing the device of GLWindow and off-screen GLAutoDrawable using FBO and PBuffer in JOGL.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Specifies an immutable set of OpenGL capabilities.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.