1

My program compiles fine but when I run it, it crashes at glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) saying:

Unhandled exception at 0x50D6C94E (nvoglv32.dll) in Chapter 2.exe: 0xC0000005: Access violation reading location 0x00000000.

A page also appears that says nvoglv32.pdb is not loaded. I checked to see if the pointers and values I passed were correct, and assert did not pick up anything.

Here's the code

Example.h

#include <windows.h>
#include "Example.h"
#include <iostream>
#include <gl\GLU.h>
#include <gl\glext.h>
#include "BufferUtilities.h"

bool Example::init()
{
    if (!start())
    {
        return false;
    }

    glEnable(GL_DEPTH_TEST);
    glClearColor(0.5f, 0.5f, 0.5f, 0.5f);

    GLfloat verticies[] = {
        -2.0f, -2.0f, -2.0f,
        2.0f, -2.0f, -2.0f,
        -2.0f, -2.0f, 2.0f,
        2.0f, -2.0f, 2.0f,
    };

    GLfloat colors[] = {
        1.0f, 0.0f, 0.0f,
        0.0f, 1.0f, 0.0f,
        0.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 0.0f,
    };

    createArrayBuffer(verticies, &vertexBuffer, GL_STATIC_DRAW);
    createArrayBuffer(colors, &colorBuffer, GL_STATIC_DRAW);

    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);

    return true;
}

void Example::render()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    bindAndPoint(&colorBuffer, 3);

    bindAndPoint(&vertexBuffer, 3);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

BufferUtilities.h

#pragma once

#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>
#include <gl\GLEXT.h>
#include <gl\wglext.h>
#include <iostream>
#include <assert.h>

#define BUFFER_OFFSET(i) ((char *)NULL+(i))

static PFNGLGENBUFFERSARBPROC glGenBuffers = NULL;
static PFNGLBINDBUFFERPROC glBindBuffer = NULL;
static PFNGLBUFFERDATAPROC glBufferData = NULL;

inline bool start()
{
    glGenBuffers = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffers");
    glBindBuffer = (PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer");
    glBufferData = (PFNGLBUFFERDATAPROC)wglGetProcAddress("glBufferData");  

    if (!glGenBuffers|| !glBindBuffer || !glBufferData)
    {
        std::cerr << "Vertex buffer objects are not supported by your graphics card." << std::endl;
        return false;
    }

    return true;
}

inline void createArrayBuffer(GLfloat *array, GLuint *buffer, GLenum usage)
{
    assert(array != NULL);
    assert(buffer != NULL);
    assert(usage != NULL);

    glGenBuffers(1, buffer);
    glBindBuffer(GL_ARRAY_BUFFER, *buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * (sizeof(array) / sizeof(array[0])), &array[0], usage);
}

inline void bindAndPoint(GLuint *buffer, int size)
{
    assert(buffer != NULL);
    assert(size != NULL);

    glBindBuffer(GL_ARRAY_BUFFER, *buffer);
    glColorPointer(size, GL_FLOAT, 0, BUFFER_OFFSET(0));
}
Ghilliedrone
  • 85
  • 1
  • 1
  • 12
  • What operating system are you running this on? How have you set up OpenGL in the first place? Edit: nevermind you are on Windows using GLU – MrSynAckSter Jul 02 '14 at 20:06

1 Answers1

4

From a moderator on the Nvidia open GL forum: https://devtalk.nvidia.com/default/topic/720651/access-violation-in-nvoglv32-dll-how-do-i-track-down-the-problem-/

"Access violations during glDrawArrays or glDrawElements are most often due to incorrectly enabled vertex attribute arrays. Please check your current state of the enabled vertex attributes very carefully. One which is left enabled inadvertently without providing any or enough data will result in these kinds of errors when sourcing data out of bounds during the draw call.

If that's not it, maybe there is some problem with memory consumption. You're running a 32-bit app according to the DLL name. Does the same thing happen in a 64-bit version?"

The main reason this sort of thing happens is that you have not set up your draw call correctly.

A second possibility is the scenario found in this S/O post: Crash at draw call in nvoglv32.dll on new video card

In this example, the user has not initialized Open GL correctly, and it is causing the problem.

Those are two major problems that could be plaguing you. From what I am reading of your source code, it doesn't look as if you have given Draw Arrays any bad arguments, but I would investigate to ensure that your VBOs are being bound properly.

Now, I may be reading your code wrong, but in:

inline void bindAndPoint(GLuint *buffer, int size)
{
    assert(buffer != NULL);
    assert(size != NULL);

    glBindBuffer(GL_ARRAY_BUFFER, *buffer);
    glColorPointer(size, GL_FLOAT, 0, BUFFER_OFFSET(0));
}

Shouldn't there be some call to glVertexAttribPointer? I see binding, but not pointing.

If you aren't giving the Vertex Attributes over to the shader, the render shall crash.

Community
  • 1
  • 1
MrSynAckSter
  • 1,681
  • 1
  • 18
  • 34