仅在发布模式下使用glGenBuffer的未处理异常 - QT(Unhandled Exception using glGenBuffer on Release mode only - QT)

我在使用Qt 4.8在发布模式下在Windows 7上编译我的项目时遇到了一些麻烦。 在Debug上一切正常,但在Release上我得到一个未处理的异常:0xC0000005:访问冲突。

我将它缩小到发生这种情况的行,这是我生成Pixel Buffers的时候。 我的第一个猜测是错误的DLL加载,但我检查了可执行文件与Dependency Walker,并且每个加载的DLL都是正确的。

这里有一些我的代码:

class CameraView : public QGLWidget, protected QGLFunctions; void CameraView::initializeGL() { initializeGLFunctions(this->context()); glGenBuffers(1, &pbo_); //<<<<< This is where I get the unhandled exception on Release mode glBindBuffer(QGLBuffer::PixelUnpackBuffer, pbo_); glBufferData(QGLBuffer::PixelUnpackBuffer, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); ... }

同样,这在调试时非常有用。 为什么这只会发布在Release上?

I'm having some trouble while compiling my project on Windows 7 using Qt 4.8 on Release mode. Everything works fine on Debug, but on Release I get an Unhandled Exception: 0xC0000005: Access violation.

I narrowed it down to the line where this happens, which is when I generate my Pixel Buffers. My first guess would be wrong DLLs loading, but I checked the executable with Dependency Walker and every DLL loaded is correct.

Here goes some of my code:

class CameraView : public QGLWidget, protected QGLFunctions; void CameraView::initializeGL() { initializeGLFunctions(this->context()); glGenBuffers(1, &pbo_); //<<<<< This is where I get the unhandled exception on Release mode glBindBuffer(QGLBuffer::PixelUnpackBuffer, pbo_); glBufferData(QGLBuffer::PixelUnpackBuffer, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); ... }

Again, this works great on debug. Why would this only happen on Release?

最满意答案

我知道了。 似乎这个问题与这个问题有关: https : //forum.qt.io/topic/12492/qt-4-8-qglfunctions-functions-crash-in-release-build

并且还有一个可能与之相关的错误报告: https : //bugreports.qt.io/browse/QTBUG-5729

也许initializeGLFunctions()方法没有得到GL扩展函数的所有函数指针,我真的不知道为什么,但这似乎是它。

我的解决方案是停止使用Qt的GL扩展并开始使用glew。

那么,这对我有用:

#include <QtGui/QtGui> #include <gl/glew.h> #include <QtOpenGL/QGLWidget> class CameraView : public QGLWidget; void CameraView::initializeGL() { //initializeGLFunctions(this->context()); GLenum init = glewInit(); // Create buffers glGenBuffers(1, &pbo_); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_); glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); // Set matrixes glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(0, this->width(), 0, this->height(), 0, 1); glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }

确保在任何QTOpenGL标头之前包含glew.h,否则您将收到编译错误。

I got it. Seems like this issue is related to this one: https://forum.qt.io/topic/12492/qt-4-8-qglfunctions-functions-crash-in-release-build

and there's a bug report that may be related also: https://bugreports.qt.io/browse/QTBUG-5729

Perhaps the initializeGLFunctions() method is not getting all function pointers for the GL extension functions, I don't really know why but this seems to be it.

The solution for me was to stop using Qt's GL extensions and start using glew.

So, here's what worked for me:

#include <QtGui/QtGui> #include <gl/glew.h> #include <QtOpenGL/QGLWidget> class CameraView : public QGLWidget; void CameraView::initializeGL() { //initializeGLFunctions(this->context()); GLenum init = glewInit(); // Create buffers glGenBuffers(1, &pbo_); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_); glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); // Set matrixes glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(0, this->width(), 0, this->height(), 0, 1); glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }

Be sure that glew.h is included before any QTOpenGL headers or else you'll get a compilation error.

仅在发布模式下使用glGenBuffer的未处理异常 - QT(Unhandled Exception using glGenBuffer on Release mode only - QT)

我在使用Qt 4.8在发布模式下在Windows 7上编译我的项目时遇到了一些麻烦。 在Debug上一切正常,但在Release上我得到一个未处理的异常:0xC0000005:访问冲突。

我将它缩小到发生这种情况的行,这是我生成Pixel Buffers的时候。 我的第一个猜测是错误的DLL加载,但我检查了可执行文件与Dependency Walker,并且每个加载的DLL都是正确的。

这里有一些我的代码:

class CameraView : public QGLWidget, protected QGLFunctions; void CameraView::initializeGL() { initializeGLFunctions(this->context()); glGenBuffers(1, &pbo_); //<<<<< This is where I get the unhandled exception on Release mode glBindBuffer(QGLBuffer::PixelUnpackBuffer, pbo_); glBufferData(QGLBuffer::PixelUnpackBuffer, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); ... }

同样,这在调试时非常有用。 为什么这只会发布在Release上?

I'm having some trouble while compiling my project on Windows 7 using Qt 4.8 on Release mode. Everything works fine on Debug, but on Release I get an Unhandled Exception: 0xC0000005: Access violation.

I narrowed it down to the line where this happens, which is when I generate my Pixel Buffers. My first guess would be wrong DLLs loading, but I checked the executable with Dependency Walker and every DLL loaded is correct.

Here goes some of my code:

class CameraView : public QGLWidget, protected QGLFunctions; void CameraView::initializeGL() { initializeGLFunctions(this->context()); glGenBuffers(1, &pbo_); //<<<<< This is where I get the unhandled exception on Release mode glBindBuffer(QGLBuffer::PixelUnpackBuffer, pbo_); glBufferData(QGLBuffer::PixelUnpackBuffer, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); ... }

Again, this works great on debug. Why would this only happen on Release?

最满意答案

我知道了。 似乎这个问题与这个问题有关: https : //forum.qt.io/topic/12492/qt-4-8-qglfunctions-functions-crash-in-release-build

并且还有一个可能与之相关的错误报告: https : //bugreports.qt.io/browse/QTBUG-5729

也许initializeGLFunctions()方法没有得到GL扩展函数的所有函数指针,我真的不知道为什么,但这似乎是它。

我的解决方案是停止使用Qt的GL扩展并开始使用glew。

那么,这对我有用:

#include <QtGui/QtGui> #include <gl/glew.h> #include <QtOpenGL/QGLWidget> class CameraView : public QGLWidget; void CameraView::initializeGL() { //initializeGLFunctions(this->context()); GLenum init = glewInit(); // Create buffers glGenBuffers(1, &pbo_); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_); glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); // Set matrixes glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(0, this->width(), 0, this->height(), 0, 1); glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }

确保在任何QTOpenGL标头之前包含glew.h,否则您将收到编译错误。

I got it. Seems like this issue is related to this one: https://forum.qt.io/topic/12492/qt-4-8-qglfunctions-functions-crash-in-release-build

and there's a bug report that may be related also: https://bugreports.qt.io/browse/QTBUG-5729

Perhaps the initializeGLFunctions() method is not getting all function pointers for the GL extension functions, I don't really know why but this seems to be it.

The solution for me was to stop using Qt's GL extensions and start using glew.

So, here's what worked for me:

#include <QtGui/QtGui> #include <gl/glew.h> #include <QtOpenGL/QGLWidget> class CameraView : public QGLWidget; void CameraView::initializeGL() { //initializeGLFunctions(this->context()); GLenum init = glewInit(); // Create buffers glGenBuffers(1, &pbo_); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_); glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW); // Set matrixes glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(0, this->width(), 0, this->height(), 0, 1); glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }

Be sure that glew.h is included before any QTOpenGL headers or else you'll get a compilation error.