1

I've been trying to implement VBO on my computer and I ran into a segmentation fault:

Unhandled exception at 0x00000000 in attocube.exe: 0xC0000005: Access violation

The error is at the line where I call glBindBuffer(GL_ARRAY_BUFFER, ID); in void init(). I've used the code of the following question: How to get VBO working

#include <windows.h>
#include <iostream>
#include <GL/glew.h>
#include <GL/freeglut.h>

#pragma comment(lib,"glew32.lib")

GLuint ID;

void init(){
    glewInit();
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glShadeModel(GL_FLAT);
    glEnableClientState(GL_VERTEX_ARRAY);
    float data[][2] = {{50,50},{100,50},{75,100}};
    glGenBuffers(1,&ID);
    glBindBuffer(GL_ARRAY_BUFFER, ID);
    glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
}

void reshape(int w, int h){
    glViewport(0,0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0f, (GLdouble) w, 0.0f, (GLdouble) h);
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0f,0.0f,0.0f);
    glBindBuffer(GL_ARRAY_BUFFER, ID);
    glVertexPointer(2, GL_FLOAT, 2*sizeof(float), 0);
    glDrawArrays(GL_TRIANGLES,0,3);
    glFlush();  
}

int main(int argc, char **argv){
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(300,300);
    glutCreateWindow(argv[0]);
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
}

My configuration is the following: Windows 7 / Geforce GTX 570 / glew 1.9.0

Community
  • 1
  • 1
arnaud13
  • 109
  • 1
  • 2
  • 11
  • Works for me. Does your `glewInit()` call succeed? – genpfault Oct 04 '12 at 22:22
  • I've put this `GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); }` and got no error message. – arnaud13 Oct 04 '12 at 22:28
  • Could you please add the following after GLEW initialization `fprintf(stderr, "Address of glBindBuffer: %p\n", glBindBuffer);` and tell us the output. – datenwolf Oct 04 '12 at 22:33
  • Also a good diagnostic could be the content of `glGetString(GL_RENDERER);` – datenwolf Oct 04 '12 at 22:34

6 Answers6

2

Your code lacks any checks on the availability of the required OpenGL version (or in the case you made use of extensions, if the extensions are present). You always must check if requested functionality is actually present.

See the 2nd paragraph of http://glew.sourceforge.net/basic.html

Now Vertex Buffer Objects are a really widespread feature and its very unlikely for them not to be available. But the crash indicates this is the very problem. So make sure you got the proper drivers correctly installed.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • He's on a GeForce 570; you can't find drivers old enough for such hardware that don't support better than GL 1.5. You probably can't find drivers that don't support GL 4.0. – Nicol Bolas Oct 04 '12 at 22:18
  • 1
    @NicolBolas: Right. But: Are the drivers correctly installed? Windows 7 by itself only brings that poor OpenGL-1.4 on Direct3D layer, *which does not support VBOs!* (As you know VBOs have been introduced with GL 1.5). So the solution is to go to the NVidia website, download the fully featured driver and install that, instead of the version stripped down by Microsoft. – datenwolf Oct 04 '12 at 22:26
  • I've already updated the driver of my graphic card to the version 306.23. – arnaud13 Oct 04 '12 at 22:31
1

I am working on the workstation with Remote Desktop Connection. I've just tried running the code directly on the machine and it works. VBO doesn't work with RDC. I'm feeling really stupid. Thank you very much for the help.

arnaud13
  • 109
  • 1
  • 2
  • 11
  • 3
    Well, it's not really a surprise: RDC doesn't do its graphics on the GPU. So this means the low-featured fallback OpenGL implementation of Windows 7, which supports only OpenGL-1.4 kicks in. There's little you can do about it. You could drop in Mesa's software renderer opengl32.dll if your program detects being run in a RDC environment, but performance will be poor. – datenwolf Oct 04 '12 at 22:37
  • I don't think I'll start messing with RDC. I'll develop my program for standard users. Thank you for the help. – arnaud13 Oct 04 '12 at 22:40
0

I had the same problem using GL < 4.0. Setting glewExperimental = GL_TRUE; just before glewInit(); solved it.

cel
  • 153
  • 5
0

Anyway, remote desktop issue apart, the code to check for VBO using GLEW is this:

bool hasVBO = GLEW_ARB_vertex_buffer_object == TRUE;
bool hasVAO = GLEW_ARB_vertex_array_object == TRUE;
Sga
  • 3,608
  • 2
  • 36
  • 47
0

To those of you who are still having difficulty with this problem, your program will crash if you call glBindBuffer from another thread that is not the render thread. At least when working with Allegro 5, anyway. I fixed this by moving my VBO code to the main thread, and the crashing stopped.

Jsnman
  • 11
  • 3
0

I got remote desktop to work between two Win7 PC's, running OpenGL 4.3:

In a batch file, put:

tscon 1 /dest:console /PASSWORD:yourPassword
cd C:\your\Exe\Folder
start yourProgram.exe
C:\Windows\System32\rundll32.exe user32.dll,LockWorkStation

Run it as administrator. It will close the session, open the console (your PC is now logged-in, for anyone to walk up and use as-you), start the program, and lock the screen.

Then you will re-connect using Remote Desktop; and your program should be running, using the server's graphics hardware acceleration.

This assumes your remote session is ID 1. To check, run command window "query session", and see the line starting with ">".

PaulQ
  • 308
  • 2
  • 9