glDeleteBuffers()在析构函数调用期间崩溃 [英] glDeleteBuffers() crashes during destructor call

查看:345
本文介绍了glDeleteBuffers()在析构函数调用期间崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如Qt用户所知,使用任何OpenGL扩展都可能很麻烦.我的工作方式是像这样扩展QGLFunctions类:

As Qt users know, using any OpenGL extensions can be quite troublesome. The way I made it work is to extends QGLFunctions class like so:

 class Object3D : protected QGLFunctions{ 
 ... 
 }

为了使Object3D正常运行,以便可以调用诸如glGenBuffer()之类的函数,需要调用

In order for Object3D to function correctly such that it can call functions like glGenBuffer() etc. one needs to call

initializeGLFunctions(glWidget->context());

已经创建了QGLWidget,否则使用任何扩展功能时,它只会使应用程序崩溃.虽然我最终可以在存在Object3D的情况下调用"glGenBuffer()"和其他名称,但似乎在包含"glDeleteBuffer()"调用的〜Object3D()调用时崩溃了.我确定正是那个调用使应用程序崩溃了.

AFTER QGLWidget has been created or else it would simply crash the application when it uses any extension functions. While I can finally call "glGenBuffer()" and others during the existence of Object3D, it seems to crash upon ~Object3D() call which contains "glDeleteBuffer()" call. I am sure it is that call that makes the application crashes.

有人知道如何解决这个问题吗?我怀疑这是因为QGLWidget首先在Object3D之前被删除,因此QGLWidget的上下文消失了.如果是这样,我怎么能确保自从QGLWidget添加到QMainWindow以来,QGLWidget最后删除了?QMainWindow只是按照添加顺序删除了其子级?

Anyone know how to solve this problem? I suspect it is because QGLWidget is being deleted first before Object3D and so the context of QGLWidget is gone. If that's the case, how can I make sure QGLWidget is deleted last since QGLWidget is added to QMainWindow which simply deletes its children in the order they are added?

推荐答案

一般规则是,如果不能保证,则在上下文仍然存在的情况下将销毁OpenGL RAII对象,然后不要将OpenGL对象包装在RAII C ++类中.通过其他方式管理OpenGL对象的生存期.

The general rule is, if you can't guarantee that the OpenGL RAII object will be destroyed while the context is still around, then don't wrap OpenGL objects inside RAII C++ classes. Manage the lifetime of OpenGL objects in other ways.

这是您的代码(您忽略了向我们展示);只有您可以决定在哪里或如何管理类的销毁.您需要一些系统来管理您的对象,以确保按照正确的顺序销毁(创建)事物.

It's your code (which you neglected to show us); only you can decide where or how to manage the destruction of classes. You need some system to manage your objects that will ensure that things are destroyed (and created) in the proper order.

这篇关于glDeleteBuffers()在析构函数调用期间崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆