INVALID_OPERATION

Okay… I got this error, and I have absolutely no clue what it might be caused by. My code is more or less directly taken from NeHe tutorial jogl example code, since I’ve gone back step by step in order to track that bug. Didn’t work out.

Some code:
init function, should be self-explaining


        this.drawable = drawable;
        // we do this manually (in show()), so it's steadily done at the end of each tick
        drawable.setAutoSwapBufferMode(false);

        // get generic GLU :)
        this.glu = new GLU();

        drawable.setGL(new DebugGL(drawable.getGL()));
        this.gl = drawable.getGL();

        gl.glEnable(GL.GL_TEXTURE_2D);
        gl.glShadeModel(GL.GL_SMOOTH);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);

        this.gl = null;

display method, interesting comments with !!!


        // get surface
        gl = drawable.getGL();
        
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

        // go through queue and draw

        // !!! in the second tick, the texture gets generated and bound here. nothing else to say, all other functionality gone for debugging
        if(blah == null)
            while(!queue.isEmpty())
                // draw each element of this
                queue.remove().draw(this);

        try {

            gl.glMatrixMode(GL.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0.0f,0.0f,-5.0f);

            // !!! blah is the texture (wrapped up in a simple class), in the first tick it's null, (draws red square), second tick it's there
            if(blah == null) {

                gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

                gl.glBegin(GL.GL_QUADS); {
                    gl.glColor3f(1.0f, 0.0f, 0.0f);
                    gl.glVertex3f(-1.0f, -1.0f,  1.0f);
                    gl.glVertex3f( 1.0f, -1.0f,  1.0f);
                    gl.glVertex3f( 1.0f,  1.0f,  1.0f);
                    gl.glVertex3f(-1.0f,  1.0f,  1.0f);
                } gl.glEnd();

            } else {


                gl.glColor3f(0.0f, 1.0f, 1.0f);
                // !!! simply binds texture, nothing else. checked a thousand times for errors
                blah.bind(gl);

                gl.glBegin(GL.GL_QUADS); {

                    // !!! code 1:1 from tutorial, the square is shown, but it's plain color
                    gl.glTexCoord2f(0.0f, 0.0f);
                    gl.glVertex3f(-1.0f, -1.0f,  1.0f);

                    gl.glTexCoord2f(1.0f, 0.0f);
                    gl.glVertex3f( 1.0f, -1.0f,  1.0f);

                    gl.glTexCoord2f(1.0f, 1.0f);
                    gl.glVertex3f( 1.0f,  1.0f,  1.0f);

                    gl.glTexCoord2f(0.0f, 1.0f);
                    gl.glVertex3f(-1.0f,  1.0f,  1.0f);

                // !!! this glEnd gives the error (see below), but only in the tick after the texture is generated. after that, a solid square is drawn.
                } gl.glEnd();
            }
        } catch (GLException e) {
            e.printStackTrace();
        }

       // pass stuff to graka
        gl.glFlush();

        // make sure outside this procedure, no gl is called.
        gl = null;

reshape


        this.gl = drawable.getGL();

        final float h = (float)width / (float)height;

        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(45.0f, h, 1.0, 20.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();

        this.gl = null;

texture making code, only the important bits. everything else is a-ok.


        // !!! serialized the byte[] array and put into the lesson06 code, it works, so up to here it's all right.
        imageBuffer = ByteBuffer.allocateDirect(data.length);
        imageBuffer.order(ByteOrder.nativeOrder());
        imageBuffer.put(data, 0, data.length);

        imageBuffer.rewind();
        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, texWidth, texHeight, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, imageBuffer);

given error


javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glEnd(): GL_INVALID_OPERATION 
	at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:11724)
	at javax.media.opengl.DebugGL.glEnd(DebugGL.java:1816)
	at com.mugenguild.vMugen.graphics.OglDisplay.display(OglDisplay.java:244)
	at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
	at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
	at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:258)
	at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
	at javax.media.opengl.GLCanvas.paint(GLCanvas.java:142)
	at sun.awt.RepaintArea.paintComponent(Unknown Source)
	at sun.awt.RepaintArea.paint(Unknown Source)
	at sun.awt.windows.WComponentPeer.handleEvent(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)
javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glEnd(): GL_INVALID_OPERATION 
	at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:11724)
	at javax.media.opengl.DebugGL.glEnd(DebugGL.java:1816)
	at com.mugenguild.vMugen.graphics.OglDisplay.display(OglDisplay.java:266)
	at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
	at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
	at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:298)
	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)

wtf?! I’ve been shooting trouble for like, 5 hours now, and I can’t seem to find any error. the only difference left, is that the texture is bound during the display routine instead of the init routine. but that can’t be it… nuh?

…anyone?

You draw like this:


        gl.glBegin(GL.GL_QUADS);
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(cornersF[0][0],cornersF[0][1],cornersF[0][2]);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(cornersF[1][0],cornersF[1][1],cornersF[1][2]);
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(cornersF[2][0],cornersF[2][1],cornersF[2][2]);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(cornersF[3][0],cornersF[3][1],cornersF[3][2]);
        gl.glEnd();

No brackets, not sure if this is what the problem is tho

Since you aren’t getting an OpenGL error earlier in your execution you need to trim down your rendering until you isolate exactly the sequence of calls provoking the error. It isn’t obvious from the code you posted where the error is (or in fact if the error is there or in another part of your code, for example the texture handling code).

you can use brackets whereever you like, with local vars and stuff. and for indentation and readability, I think putting glBegin and glEnd into brackets makes sense :slight_smile:

well, it more or less is. the queue loop (almost) directly calls the texture binding code. I’ll try to get it all in a sequence like you said, though. Thanks for helping :slight_smile:

Heh, wasn’t sure if it would affect it or not, maybe I shouldn’t be giving advice as a JOGL newb :-X

Good luck with fixing the problem

changed the code a bit to have all gl calls in one sequence.


        // go through queue and draw
       // !!! I changed this. there are no ogl calls in here at all now, only thing it does is generate the bytebuffer
        if(blah == null)
            while(!queue.isEmpty())
                // draw each element of this
                queue.remove().draw(this);

        try {

            gl.glMatrixMode(GL.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0.0f,0.0f,-5.0f);

            if(blah == null) {

                gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

                gl.glBegin(GL.GL_QUADS); {
                    gl.glColor3f(1.0f, 0.0f, 0.0f);
                    gl.glVertex3f(-1.0f, -1.0f,  1.0f);
                    gl.glVertex3f( 1.0f, -1.0f,  1.0f);
                    gl.glVertex3f( 1.0f,  1.0f,  1.0f);
                    gl.glVertex3f(-1.0f,  1.0f,  1.0f);
                } gl.glEnd();

            } else {
                // results in a call glBindTexture with id 1, nothing wrong here
                blah.bind(gl);

                blah.textureBuffer.rewind();
                // !!! in this line (below), an exception is shown, see below. wtf!
                gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, blah.texWidth, blah.texHeight, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, blah.textureBuffer);

                gl.glColor3f(0.0f, 1.0f, 1.0f);

                gl.glBegin(GL.GL_QUADS); {

                    gl.glTexCoord2f(0.0f, 0.0f);
                    gl.glVertex3f(-1.0f, -1.0f,  1.0f);

                    gl.glTexCoord2f(1.0f, 0.0f);
                    gl.glVertex3f( 1.0f, -1.0f,  1.0f);

                    gl.glTexCoord2f(1.0f, 1.0f);
                    gl.glVertex3f( 1.0f,  1.0f,  1.0f);

                    gl.glTexCoord2f(0.0f, 1.0f);
                    gl.glVertex3f(-1.0f,  1.0f,  1.0f);

                } gl.glEnd();
            }

exception thrown:


java.lang.NullPointerException
	at com.sun.opengl.impl.FunctionAvailabilityCache$Version.<init>(FunctionAvailabilityCache.java:296)
	at com.sun.opengl.impl.FunctionAvailabilityCache.initAvailableExtensions(FunctionAvailabilityCache.java:133)
	at com.sun.opengl.impl.FunctionAvailabilityCache.isExtensionAvailable(FunctionAvailabilityCache.java:104)
	at com.sun.opengl.impl.GLContextImpl.isExtensionAvailable(GLContextImpl.java:337)
	at com.sun.opengl.impl.GLImpl.isExtensionAvailable(GLImpl.java:27851)
	at com.sun.opengl.impl.GLImpl.initBufferObjectExtensionChecks(GLImpl.java:27994)
	at com.sun.opengl.impl.GLImpl.checkUnpackPBODisabled(GLImpl.java:28027)
	at com.sun.opengl.impl.GLImpl.glTexImage2D(GLImpl.java:19578)
	at javax.media.opengl.DebugGL.glTexImage2D(DebugGL.java:8445)
	at com.mugenguild.vMugen.graphics.OglDisplay.display(OglDisplay.java:250)
	at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
	at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
	at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
	at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:298)
	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)

I have absolutely no idea what this could mean. The ByteBuffer is not null (I checked in the debugger, it’s all how it’s supposed to be, and also the nullpointerexception doesn’t occur at the rewind), texwidth results to 64, texheight results to 128, all other parameters are constants. there were no exceptions caught where this call was made before

also, the exception looks more like a function is missing or something within the ogl libs… hum. any ideas?

no, why? it was an idea, and you learned something. nothing wrong there :wink:

\ edit

almost the same error msg here, so I guess it’s not my code that is causing the problem…
http://www.java-gaming.org/forums/index.php?topic=13705.0

:slight_smile:

\\ edit

ARRGH!!!

I forgot to put a glEnd() at the end of a drawLine call, which I didn’t even know was executed!! this, and the bug, made up for a perfect combination to keep me entertained, really >_<

\\ edit

fuckin’ woot. it’s working now. thanks, everyone =)