Posted by
gouessej on
Oct 14, 2011; 3:28pm
URL: https://forum.jogamp.org/Some-crashes-on-Ubuntu-9-04-jaunty-with-SWT-GLCanvas-and-AWT-GLCanvas-tp3422020.html
Hi
Someone contacted me because he gave a try to the experimental SWT GLCanvas of JOGL 2.0 and the same snippet working on Windows 64 bits crashes on Ubuntu Linux 32 bits :
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLProfile;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.media.opengl.glu.GLU;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
/**
*
* @author Pierre ******
* @since 29 sept. 2011
*/
class Snippet209 {
static {
GLProfile.initSingleton(false);
}
/**
* @param gl
* @param r
* @param R
* @param nsides
* @param rings
*/
static void drawTorus(GL2 gl, float r, float R, int nsides, int rings) {
float ringDelta = 2.0f * (float) Math.PI / rings;
float sideDelta = 2.0f * (float) Math.PI / nsides;
float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
for (int i = rings - 1; i >= 0; i--) {
float theta1 = theta + ringDelta;
float cosTheta1 = (float) Math.cos(theta1);
float sinTheta1 = (float) Math.sin(theta1);
gl.glBegin(GL2.GL_QUAD_STRIP);
float phi = 0.0f;
for (int j = nsides; j >= 0; j--) {
phi += sideDelta;
float cosPhi = (float) Math.cos(phi);
float sinPhi = (float) Math.sin(phi);
float dist = R + r * cosPhi;
gl.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
gl.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
}
gl.glEnd();
theta = theta1;
cosTheta = cosTheta1;
sinTheta = sinTheta1;
}
}
/**
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new FillLayout());
// final SWTGLCanvas canvas = new SWTGLCanvas(comp, SWT.NONE,
// GLProfile.get(GLProfile.GL2));
final SWTGLCanvas canvas = new SWTGLCanvas(comp, SWT.NONE,
GLProfile.getDefault());
canvas.makeCurrent();
canvas.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
Rectangle bounds = canvas.getBounds();
float fAspect = (float) bounds.width / (float) bounds.height;
canvas.makeCurrent();
GL2 gl = canvas.getContext().getGL().getGL2();
gl.glViewport(0, 0, bounds.width, bounds.height);
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
GLU glu = new GLU();
glu.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
canvas.releaseContext();
}
});
canvas.makeCurrent();
GL2 gl = canvas.getContext().getGL().getGL2();
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glClearDepth(1.0);
gl.glLineWidth(2);
gl.glEnable(GL.GL_DEPTH_TEST);
canvas.releaseContext();
shell.setText("SWT/JOGL Example");
shell.setSize(640, 480);
shell.open();
display.asyncExec(new Runnable() {
int rot = 0;
@Override
public void run() {
if (!canvas.isDisposed()) {
canvas.makeCurrent();
GL2 gl = canvas.getContext().getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glClearColor(.3f, .5f, .8f, 1.0f);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -10.0f);
float frot = rot;
gl.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
gl.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
rot++;
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
gl.glColor3f(0.9f, 0.9f, 0.9f);
drawTorus(gl, 1,
1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
canvas.swapBuffers();
canvas.releaseContext();
display.asyncExec(this);
try {
Thread.sleep(50);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
He gets this each time:
Info: XInitThreads() called for concurrent Thread support
Exception in thread "main" javax.media.opengl.GLException: Error making temp context(1) current: display 0xffffffff90791278, context 0xffffffff9073ce30, drawable jogamp.opengl.x11.glx.X11OnscreenGLXDrawable[Realized true,
Factory jogamp.opengl.x11.glx.X11GLXDrawableFactory@1041876,
handle 0x3e0002d,
Window WrappedSurface[config X11GLXGraphicsConfiguration[X11GraphicsScreen[X11GraphicsDevice[type X11, connection :0.0, unitID 0, handle 0xffffffff90791278], idx 0], visualID 0x58, fbConfigID 0x58,
requested GLCaps[on-scr, rgba 0x8/8/8/1, opaque, accum-rgba 0/0/0/0, dp/st/ms: 16/0/2, dbl, mono , hw, GLProfile[GL2/GL2]],
chosen GLCaps[0x58 0x58: on-scr, rgba 0x8/8/8/8, trans-rgba 0xff/ff/ff/ff, accum-rgba 0/0/0/0, dp/st/ms: 16/0/0, dbl, mono , hw, GLProfile[GL2/GL2]]], displayHandle 0xffffffff90791278, surfaceHandle 0x3e0002d, size 640x480]]
at jogamp.opengl.x11.glx.X11GLXContext.createImplRaw(X11GLXContext.java:356)
at jogamp.opengl.x11.glx.X11GLXContext.createImpl(X11GLXContext.java:285)
at jogamp.opengl.GLContextImpl.makeCurrentLocking(GLContextImpl.java:451)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:388)
at fr.volutes.ui.editors.SWTGLCanvas.makeCurrent(SWTGLCanvas.java:96)
at fr.volutes.ui.editors.Snippet209.main(Snippet209.java:87)
When he uses the AWT GLCanvas on the same machine with Ubuntu Linux, it works but when he tries to reopen another GLCanvas, he gets this: (please find enclosed the logs)
awtcanvas_hs_err_pid4681.logCan someone help us? I suspect a driver bug in the last case.