Posted by
karelknoes on
Sep 10, 2013; 7:48am
URL: https://forum.jogamp.org/JOGL-2-0-2-crash-on-Mac-OS-X-10-6-8-tp4029795p4030009.html
I've attached our code to reproduce the problem for Mac OS X 10.6 (it's also included with Bug 818). As said above, the use of GLJPanel hard crashes the JVM. We appeciate any tips / accessible work that might get us moving again, because our migration to the newest jogl is unfortunately blocked on this issue.
import java.awt.Dimension;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.awt.GLJPanel;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.swing.JApplet;
import javax.swing.JPanel;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;
public class SimpleApplet extends JApplet {
private static final long serialVersionUID = 1L;
private Animator animatorCanvas;
private Animator animatorPanel;
@Override
public void init() {
final JPanel panel = new JPanel();
setContentPane(panel);
final GLCanvas glCanvas = new GLCanvas();
glCanvas.addGLEventListener(new JOGLQuad(true));
animatorCanvas = new Animator(glCanvas);
glCanvas.setPreferredSize(new Dimension(300, 300));
panel.add(glCanvas);
final GLJPanel gljPanel = new GLJPanel();
gljPanel.addGLEventListener(new JOGLQuad(false));
animatorPanel = new Animator(gljPanel);
gljPanel.setPreferredSize(new Dimension(300, 300));
panel.add(gljPanel);
}
@Override
public void start() {
animatorCanvas.start();
animatorPanel.start();
}
@Override
public void stop() {
animatorCanvas.stop();
animatorPanel.stop();
}
@Override
public void destroy() {}
}
/**
* Self-contained example (within a single class only to keep it simple) displaying a rotating quad
*/
class JOGLQuad implements GLEventListener {
private static final float[] VERTEX_DATA = {
-1.0f, 1.0f, 0.0f, // Top Left
1.0f, 1.0f, 0.0f, // Top Right
1.0f, -1.0f, 0.0f, // Bottom Right
-1.0f, -1.0f, 0.0f // Bottom Left
};
private static final float[] TEXCOORD_DATA = {
0.0f, 1.0f, // Top Left
1.0f, 1.0f, // Top Right
1.0f, 0.0f, // Bottom Right
0.0f, 0.0f // Bottom Left
};
private FloatBuffer vertexBuf;
private FloatBuffer texCoordBuf;
private int vertexVBO;
private int texCoordVBO;
private float rotateT = 0.0f;
private boolean canvas;
private Texture texture;
JOGLQuad(boolean canvas) {
this.canvas = canvas;
ByteBuffer bb = ByteBuffer.allocateDirect(VERTEX_DATA.length * 4);
bb.order(ByteOrder.nativeOrder());
vertexBuf = bb.asFloatBuffer();
vertexBuf.put(VERTEX_DATA);
vertexBuf.rewind();
bb = ByteBuffer.allocateDirect(TEXCOORD_DATA.length * 4);
bb.order(ByteOrder.nativeOrder());
texCoordBuf = bb.asFloatBuffer();
texCoordBuf.put(TEXCOORD_DATA);
texCoordBuf.rewind();
}
@Override
public void init(GLAutoDrawable glDrawable) {
final GL2 gl = glDrawable.getGL().getGL2();
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
int[] tmp = new int[2];
gl.glGenBuffers(tmp.length, tmp, 0);
vertexVBO = tmp[0];
texCoordVBO = tmp[1];
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexVBO);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, VERTEX_DATA.length * 4, vertexBuf, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, texCoordVBO);
gl.glBufferData(GL2.GL_ARRAY_BUFFER, TEXCOORD_DATA.length * 4, texCoordBuf, GL2.GL_STATIC_DRAW);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
try {
InputStream stream = getClass().getClassLoader().getResourceAsStream("image.jpg");
texture = TextureIO.newTexture(stream, true, "JPG");
} catch (Exception exc) {
exc.printStackTrace(System.err);
}
}
@Override
public void dispose(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
int[] tmp = new int[] {vertexVBO, texCoordVBO};
gl.glGenBuffers(tmp.length, tmp, 0);
}
@Override
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
final GL2 gl = gLDrawable.getGL().getGL2();
final float aspect = (float) width / (float) height;
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
final float fh = 0.5f;
final float fw = fh * aspect;
gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
@Override
public void display(GLAutoDrawable gLDrawable) {
final GL2 gl = gLDrawable.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);
// rotate about the three axes
gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
// set the color of the quad
if (canvas) {
gl.glColor3f(0.2f, 1.0f, 1.0f);
} else {
gl.glColor3f(1.0f, 0.2f, 0.2f);
}
if (texture != null) {
texture.bind(gl);
texture.enable(gl);
} else {
System.err.println("no texture");
}
// Draw A Quad
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexVBO);
gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, texCoordVBO);
gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);
gl.glDrawArrays(GL2.GL_QUADS, 0, 4);
gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
if (texture != null) {
texture.disable(gl);
}
// increasing rotation for the next iteration
rotateT += 0.2f;
}
}