GlGenBuffers crashes to Release Build

I ran into an odd problem with the OpenGL function glGenBuffers (). I am writing a fairly simple application in which I use VBO declared as follows:

#include <QGLFunctions> #include <QGLWidget> class MyClass : public QGLWidget, protected QGLFunctions { GLuint vertexBufferObject; // ... GLuint makeBufferList(void); } GLuint MyClass::makeBufferList(void) { vertexBufferObject = 0; glGenBuffers(1, &vertexBufferObject); // <-- Here it crashes // ... load data and render return vertexBufferList; } MyClass::MyClass(QWidget* parent) : QGLWidget(parent), vertexBufferObject(0) { QGLContext* context = new QGLContext(this->format()); initializeGLFunctions(context); glInit(); } MyClass::~MyClass() { glDeleteBuffers(1, &vertexBufferObject); } 

All this works great in Debug Build. The data is obtained beautifully and that’s it, and the program ends correctly at the end. However, in Release Build, glGenBuffers () unloads the program. It does not just return 0 or does nothing, it works right when the function is called. But since the problem only occurs in Release mode, I cannot use the debugger to find out what is going wrong.

I am working on a Windows 7 system and developing in Qt 4.8.1. The compiler is the MSVC 2010 compiler (Qt SDK).

Does anyone have any suggestions that I could try?

// Edit:

It may be useful to know: I tried to compile the exact same code on a Mac using the GCC compiler (Qt SDK), and both Debug and Release Build work just fine. But in Windows 7 the problem persists.

+4
source share
1 answer

Found a problem (thanks @MahmoudFayez): the problem arises due to an error in the Qt API, which also leads to the glGenBuffers () function (and possibly others) crashing. The question is directly equivalent to the question discussed here:

The solution is relatively simple, although not very elegant: use GLEW instead of QGLFunctions. I fixed my problem as follows:

 #include "glew.h" #include <QGLWidget> class MyClass : public QGLWidget { // ...same as the above } MyClass::MyClass(QWidget* parent) : QGLWidget(parent), vertexBufferObject(0) { makeCurrent(); glewInit(); } 

It all decided. The disadvantage is that this is due to the use of an additional external dependency, while the use of Qt is associated with the greatest possible compatibility with a minimum number of external dependencies. However, it seems we need to wait until Qt 5.0 is released before this error can be fixed.

As a final comment: I could not figure out how much of this error leads to a failure only with the release of the assembly, but not in debug mode.

+4
source

All Articles