Error in calculating the getZdepth() in Applet

Started by rainforest, May 16, 2007, 22:51:26

Previous topic - Next topic

rainforest

Im trying to read a particular Z value on the AWTGLCanvas screen for a given X,Y value. But Im getting this error message:

# An unexpected error has been detected by HotSpot Virtual Machine:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00b8d6df, pid=504, tid=416
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# j  org.lwjgl.opengl.GL11.glReadPixels(IIIIIILjava/nio/ByteBuffer;)V+7
#


/* The code: from GLApp.java */
//Called during the initialization of the applet
public void initBuffers(int w, int h)
    {
        bufferZdepth = allocBytes(SIZE_FLOAT);
    }

//called on mouse click event of the applet
public static float getZDepth(int x, int y)
{       bufferZdepth.clear();
        GL11.glReadPixels(x, y, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, bufferZdepth);
        return ( (float) (bufferZdepth.getFloat(0)));
}


Any suggestions would be very helpful.
.:: A journey of thousand miles starts with a single step ::.

Matzon

what does allocBytes(SIZE_FLOAT); do ?
especially since it ignores w and h

I'm not fond of that VM crash :(

elias

He's reading one pixel of the depth buffer, and if SIZE_FLOAT is 4 I can't see anything wrong with that code. Could you post a minimal test case for us to verify? Preferably a "Display.create(), glReadPixels()" test.

- elias

rainforest

Thank u very much for your feedbacks.

I'd tried to get rid of other codes keeping the framework intact, so that it could be tested. Its a rendering of a white rectangle, clicking on the screen will fire the exception (VM: crash).

The link to the applet code :http://www.site.uottawa.ca/~arahm049/kafi/AppletJava.rar
.:: A journey of thousand miles starts with a single step ::.

elias

From the stack trace, I suspect you're running into http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342951. Please upgrade to at least jdk 1.5.0_07 or jdk 6 and try again.

- elias

rainforest

U r absolutely right, with the new J2SE update (5_11) now the JVM is not crashing. But the old exception with glReadPixel still persists  ???. Here is the exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glReadPixels(GL11.java:2252)
   at org.lwjgl.test.applet.GLmyApp.getZDepth(GLmyApp.java:42)
   at org.lwjgl.test.applet.GLAppMain.mouseDown(GLAppMain.java:60)
   at org.lwjgl.test.applet.ModelViewerRenderer.processMouseClickEvent(ModelViewerRenderer.java:76)
   at org.lwjgl.test.applet.AppletCanvas.mouseClicked(AppletCanvas.java:40)
   at org.lwjgl.test.applet.JGLPanel.mouseClicked(JGLPanel.java:48)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)

The code that Im using is from the famous <GLApp.java>. With previous library (v.98) the same code works just fine. But switching with the LWJGL 1.1 library this exception is happening.  :-\
.:: A journey of thousand miles starts with a single step ::.

elias

The NPE is thrown because no context is current (in .98 we never released the context, which was incorrect). You'll need a makeCurrent()/releaseContext() pair or simply storing the coordinates clicked and processing them in the render loop where the context is current.

Off topic: Reading the Z buffer, even a single pixel, can cause quite a slowdown on some graphics cards.

- elias

rainforest

Thank u very much for the excellent replies Elias. Those were really very helpful.
.:: A journey of thousand miles starts with a single step ::.