[SOLVED] Fatal Exception - What'd I do?

Ok, Built a VBO displaying program from scratch.

Just got it working, changed the contents of the buffers to draw a cube instead of a triangle.

Got this:


#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005c1e50d9, pid=8516, tid=8980
#
# JRE version: Java(TM) SE Runtime Environment (8.0_45-b15) (build 1.8.0_45-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [nvoglv64.DLL+0xd650d9]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# F:\Dropbox\2-Documents\4-Java Programming\Empire_Architect_0.08\hs_err_pid8516.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

What’d I do wrong?

A little research told me that this may be caused by corrupted JVM files so I completely un/re installed x86 jre, 64bit jre And 64bit jdk - no effect.

Contents of the mentioned dump log file is here:
http://pastebin.java-gaming.org/0e0c58c932d1a

My Code is getting quite extensive as I try to unravel this VBO concept. I don’t know what code to post - ask and ye shall receive.

It goes away if I comment out the following line:


glDrawArrays(GL_TRIANGLES, 0, 3);

Which, you know, is kinda… necessary…

Can you show a few lines around the glDrawArray call?

Essentially this is the equivalent of an IndexOutOfBoundsException in Java. You get it when one of the pointers you have set up tries to access some data outside of the OpenGL Buffer. Because there is no check to ensure it is in bounds, the program tries anyway and the os doesn’t let it because it doesn’t have access to that portion of memory and instead causes and access violation error.

So check your pointers. Post any calls to glVertexAttribPointer(), any calls to glBufferData() any calls to glDrawXXX().

Initialization:


        vHandle = glGenBuffers();

        // Draws a cube - 2 triangles per side - went for something simple
        vBuffer = BufferUtils.createFloatBuffer(6*3*6);
        vBuffer.put(new float[]{-1f, -1f,  -10f});// Floor
        vBuffer.put(new float[]{-1f, -1f,  +10f});
        vBuffer.put(new float[]{+1f, -1f,  +10f});
        vBuffer.put(new float[]{-1f, -1f,  -10f});// Floor
        vBuffer.put(new float[]{+1f, -1f,  -10f});
        vBuffer.put(new float[]{+1f, -1f,  +10f});
        vBuffer.put(new float[]{-1f, +1f, -10f});// Ceiling
        vBuffer.put(new float[]{-1f, +1f, +10f});
        vBuffer.put(new float[]{+1f, +1f, +10f});
        vBuffer.put(new float[]{-1f, +1f, -10f});// Ceiling
        vBuffer.put(new float[]{+1f, +1f, -10f});
        vBuffer.put(new float[]{+1f, +1f, +10f});
        vBuffer.put(new float[]{-1f, -1f,  +10f}); // Left Side
        vBuffer.put(new float[]{-1f, -1f,  -10f});
        vBuffer.put(new float[]{-1f, +1f, -10f});
        vBuffer.put(new float[]{-1f, -1f,  +10f}); // Left Side
        vBuffer.put(new float[]{-1f, +1f, +10f});
        vBuffer.put(new float[]{-1f, +1f, -10f});
        vBuffer.put(new float[]{+1f, -1f,  +10f}); // Right
        vBuffer.put(new float[]{+1f, -1f,  -10f});
        vBuffer.put(new float[]{+1f, +1f, -10f});
        vBuffer.put(new float[]{+1f, -1f,  +10f}); // Right
        vBuffer.put(new float[]{+1f, +1f, +10f});
        vBuffer.put(new float[]{+1f, +1f, -10f});
        vBuffer.put(new float[]{-1f, -1f,  +10f}); // Back
        vBuffer.put(new float[]{+1f, -1f,  +10f});
        vBuffer.put(new float[]{+1f, +1f, +10f});
        vBuffer.put(new float[]{-1f, -1f,  +10f}); // Back
        vBuffer.put(new float[]{-1f, +1f, +10f});
        vBuffer.put(new float[]{+1f, +1f, +10f});
        vBuffer.put(new float[]{-1f, -1f,  -10f}); // Front
        vBuffer.put(new float[]{+1f, -1f,  -10f});
        vBuffer.put(new float[]{+1f, +1f, -10f});
        vBuffer.put(new float[]{-1f, -1f,  -10f}); // Front
        vBuffer.put(new float[]{-1f, +1f, -10f});
        vBuffer.put(new float[]{+1f, +1f, -10f});

        glBindBufferARB(GL_ARRAY_BUFFER_ARB, vHandle);
        glBufferDataARB(GL_ARRAY_BUFFER_ARB, vBuffer, GL_STATIC_DRAW_ARB);
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);  // Unbind


drawing render loop:


        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Initialize States
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);

        glLoadIdentity();
        glScalef(scale, scale, scale); // uniform scaling
        glRotatef(rotation.pitch, 1, 0, 0);
        glRotatef(rotation.yaw,   0, 1, 0);
        glRotatef(rotation.roll,  0, 0, 1);
        glTranslatef(position.x, position.y, position.z);
        
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, vHandle);
        glBufferDataARB(GL_ARRAY_BUFFER_ARB, vBuffer, GL_STATIC_DRAW_ARB);
        glVertexPointer(3, GL_FLOAT, 1, 0L);
        
        glDrawArrays(GL_TRIANGLES, 0, 3 /* elements */);
        
        // Cleanup bound buffers
        glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
        glDeleteBuffers(vHandle);
        
        // Clean up States
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);

        // Update the display and show the drawn screen
        updateFPS();// method of my own
        Display.update();           // Tells LWJGL to render the frame
        if(getBoolean("VSYNC")){
            Display.sync(framerate);// Sets Framerate
        }


You’re telling openGL to draw 3 vertices, not 36:


glDrawArrays(GL_TRIANGLES, 0, 3 /* elements */);

and your stride (1) is wrong

glVertexPointer(3, GL_FLOAT, 1, 0L);

I do believe that is the size in bytes of each vertex, so if you have 3 floats (for position) it would be 3 * size_of_float if it was 6 (for position and color) it would be 6 * size_of_float, etc.

FYI, you’re rotating in zyx order, which is probably not what you want, the way openGL multiplies matrices means that you need to call rotate on z then y then x to get xyz rotation, not related but you’ll run into that in the future when you import meshes.

        
glRotatef(rotation.pitch, 1, 0, 0);
glRotatef(rotation.yaw,   0, 1, 0);
glRotatef(rotation.roll,  0, 0, 1);

Good Catch, can’t believe I missed that. Was thinking 3 vertexes per triangle, but I guess the GL_TRIANGLES kinda already says that. Changed it to 12 for 2 triangles per side, 6 sides.

Also good catch. I was thinking 1 element, not 1 byte. At the very least it should be 3 if I have no colors/textures/normals. Changed it back to 0 so it auto calculates for now, till I nail down this error.

I remember reading something about that but don’t remember where. Changed it for future reference.

None of these fixed the fatal error though.

glDeleteBuffers(vHandle);

Step through the program, does it fatal error the first time it draws? If not then it’s probably that line^.

Why do you enable the GL_COLOR_ARRAY if all you supply is the vertices? I think that the exception comes when you try to draw your shape because it thinks you are supplying color data when you aren’t (just from the code you supplied, at least)

DING! DING! DING! We have a winner!!! - no more fatal exception!!!

I took out the color when I replaced it with texture coordinates. Then I took texture coords out to make it simpler, and forgot this line.

Now I just get:


Java Result: -1073741819
BUILD SUCCESSFUL (total time: 4 seconds)

This line has been plaguing me for a bit too. I don’t know how I get rid of it, but I usually fiddle with things and it goes away eventually.

UPDATE: stepping through the program, I narrowed it down to this line:

 glDrawArrays(GL_TRIANGLES, 0, 12 /* elements */);

I tried various numbers for number of elements, no change.

I took these lines out previously in my many attempts to fix it. I always wondered what they were for. I just had them in due to the tutorial I was following from here on the forums.

Solved: Turns out I forgot to flip my buffer before drawing. Results looks really odd, but the error is no longer happening - it is actually drawing! Thanks @thedanisaur and @CopyableCougar4!