仅在释放模式下使用glGenBuffer的未处理异常-QT [英] Unhandled Exception using glGenBuffer on Release mode only - QT
问题描述
在Windows 7上使用发布模式下的Qt 4.8编译项目时遇到麻烦.在Debug上一切正常,但是在Release上,出现未处理的异常:0xC0000005:访问冲突.
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.
我将其范围缩小到发生这种情况的那一行,也就是我生成像素缓冲区的那一行. 我的第一个猜测是错误的DLL加载,但是我用Dependency Walker检查了可执行文件,并且每个DLL加载都正确.
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.
这是我的一些代码:
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上发生?
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
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
,并且存在一个错误报告,该错误报告还可能与相关: https://bugreports.qt.io/browse/QTBUG-5729
and there's a bug report that may be related also: https://bugreports.qt.io/browse/QTBUG-5729
也许initializeGLFunctions()方法没有获取GL扩展函数的所有函数指针,我真的不知道为什么,但是看起来确实如此.
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.
对我来说,解决方案是停止使用Qt的GL扩展,开始使用glew.
The solution for me was to stop using Qt's GL extensions and start using 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,否则会出现编译错误.
Be sure that glew.h is included before any QTOpenGL headers or else you'll get a compilation error.
这篇关于仅在释放模式下使用glGenBuffer的未处理异常-QT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!