So here’s my testcase. Just try to resizes the frame some times without releasing the mouse.
Edit: I changed the mousebuffer to have a 102410243 size as you said ((width+1)*(height+1)*3 works as well). And no exceptions occur… so why is there a problem by using real sizes? So take this testcase just as an implementation question ;D
It crashes on nvidia and intel with following error:
An unexpected error has been detected by Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77f437fe, pid=3972, tid=4060
Java VM: Java HotSpot™ Client VM (1.6.0-b105 mixed mode)
Problematic frame:
C [ntdll.dll+0x37fe]
An error report file with more information is saved as hs_err_pid3972.log
If you would like to submit a bug report, please visit:
Sometimes I get an error like: Windows detected a problem with javaw.exe…
import java.nio.ByteBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLJPanel;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;
import com.sun.opengl.util.BufferUtil;
public class ReshapeReadPixelTest {
public static boolean read = true;
/**
* @param args
*/
public static void main(String[] args) {
final GLJPanel panel = new GLJPanel();
panel.setOpaque(false);
panel.addGLEventListener(new GLEventListener() {
private ByteBuffer mouseBuffer;
private int width;
private int height;
public void display(GLAutoDrawable arg0) {
GL gl = arg0.getGL();
if (panel.shouldPreserveColorBufferIfTranslucent()) {
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
} else {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(-1, 1, 0);
gl.glVertex3f(-1, -1, 0);
gl.glVertex3f(1, -1, 0);
gl.glVertex3f(1, 1, 0);
gl.glEnd();
if (read) {
read = false;
mouseBuffer = BufferUtil.newByteBuffer(width * height * 3);
gl.glReadPixels(0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, mouseBuffer);
}
}
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
}
public void init(GLAutoDrawable arg0) {
}
public void reshape(GLAutoDrawable arg0, int x, int y, int width, int height) {
this.width = width;
this.height = height;
read = true;
GL gl = arg0.getGL();
GLU glu = new GLU();
gl.glViewport(x, y, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0, (float) width / height, 1.0, 400.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
// panel.repaint();
}
});
JFrame f = new JFrame();
f.setSize(300,300);
f.add(panel);
f.setVisible(true);
}
}