glTexImage2D explodes

Every time I try and load a texture using JOGL the VM explodes. Heres the code where its called:


public Texture getTexture(String name, 
                              String resourceName, 
                              int target, 
                              int dstPixelFormat, 
                              int minFilter, 
                              int magFilter, 
                              boolean wrap, 
                              boolean mipmapped) throws IOException 
    { 
        int srcPixelFormat = 0;
        
        // create the texture ID for this texture 
        int textureID = createTextureID(); 
        System.out.println("Loading texture "+resourceName+" to ID: "+textureID);
        Texture texture = new Texture(resourceName,target,textureID); 
 
        // bind this texture 
        gl.glBindTexture(target, textureID); 
 
        BufferedImage bufferedImage = loadImage(resourceName); 
        
        // Getting the real Width/Height of the Texture in the Memory
      int realWidth = get2Fold(bufferedImage.getWidth()); 
        int realHeight = get2Fold(bufferedImage.getHeight());
        
        
        // don't need it?
        texture.setBufferedImage(bufferedImage); 
        texture.setWidth(realWidth);
        texture.setHeight(realHeight);
        
        if (bufferedImage.getColorModel().hasAlpha()) {
            srcPixelFormat = GL.GL_RGBA;
        } else {
            srcPixelFormat = GL.GL_RGB;
        }
        
        // convert that image into a byte buffer of texture data 
        ByteBuffer textureBuffer = convertImageData(bufferedImage,texture); 
        int wrapMode = wrap ? GL.GL_REPEAT : GL.GL_CLAMP; 

        if (target == GL.GL_TEXTURE_2D) 
        { 
              gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S, wrapMode); 
              gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T, wrapMode); 
              gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, minFilter); 
              gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, magFilter);
        }
 
        // create either a series of mipmaps of a single texture image based on what's loaded 
        if (mipmapped) 
        { 
            glu.gluBuild2DMipmaps(target, 
                                  dstPixelFormat, 
                                realWidth, 
                          realHeight, 
                                  srcPixelFormat, 
                                  GL.GL_UNSIGNED_BYTE, 
                                  textureBuffer); 
        } 
        else 
        { 
            gl.glTexImage2D(target,   //<==Horrible horrible VM death
                          0, 
                          dstPixelFormat, 
                          realWidth, 
                       realHeight, 
                          0, 
                          srcPixelFormat, 
                          GL.GL_UNSIGNED_BYTE, 
                          textureBuffer ); 
        } 
 
        return texture; 
    } 

Loading texture img/props/test.png to ID: 1

An unexpected error has been detected by HotSpot Virtual Machine:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0d5611e9, pid=1868, tid=1248

Java VM: Java HotSpot™ Client VM (1.5.0_04-b05 mixed mode)

Problematic frame:

C 0x0d5611e9

An error report file with more information is saved as hs_err_pid1868.log

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

It looks like your missing some code, but my guess would be that you are not rewiding your textureBuffer before calling glTexImage2D

Hmm, forgive me for being a noob with JOGL, but what exacly is rewinding the texture buffer (conceptually, i know the syntax for it)?

After telling the buffer to rewind we get invocation target exceptions from the animator.

Thanks so much for you speedy reply!!

Also, what do you think we are missing? (again we are newbies to JOGL)

It would be:

textureBuffer .rewind();

It sets the position back to 0 so that when the texture is read, it will start at the begining, otherwise it will overflow and cause a dump like what you have.

Well, you may not be missing anything, but the source of this call wasn’t included in your post:

ByteBuffer textureBuffer = convertImageData(bufferedImage,texture);

I couldn’t tell if that was doing a rewind before returning the ByteBuffer or not.

What’s the stack trace from the animator?

it wasnt, but we fixed that. So thanks a million!!!

Heres the animator error.

Caused by: javax.media.opengl.GLException: Error making context current: 6
at com.sun.opengl.impl.windows.WindowsGLContext.makeCurrentImpl(WindowsGLContext.java:160)
at com.sun.opengl.impl.windows.WindowsPbufferGLContext.makeCurrentImpl(WindowsPbufferGLContext.java:102)
at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:74)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:117)
at com.sun.opengl.impl.GLPbufferImpl.maybeDoSingleThreadedWorkaround(GLPbufferImpl.java:197)
at com.sun.opengl.impl.GLPbufferImpl.display(GLPbufferImpl.java:88)
at javax.media.opengl.GLJPanel.paintComponent(GLJPanel.java:358)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at com.sun.opengl.utils.Animator$1.run(Animator.java:302)
at java.awt.event.InvocationEvent.dispatch(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)

We also get this problem

java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
at com.sun.opengl.utils.Animator.display(Animator.java:158)
at com.sun.opengl.utils.Animator$MainLoop.run(Animator.java:181)
at java.lang.Thread.run(Unknown Source)

I am afraid for this one you will need someone else - all the JOGL I ever did was done without the animator class (I used my own), and prior to this version of JOGL which does things a bit differently with contexts.

Ken… this ones yours :slight_smile:

Another thing, apparently in the newest distro of JOGL this doesnt work:


GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( new GLCapabilities() );

Anyone know anything about that? I need to be able to use a GLJPanel as a viewport instead of a Canvas anyways, but they are both instantiated the same way (through a factory), or at least thats how i understand it.

GLCanvas and GLJPanel now have public constructors and are instantiated independently from the GLDrawableFactory.

Regarding your exceptions above, does the JGears demo work on your system? Do you have a test case reproducing the error with making the pbuffer’s context current?