GlDeleteBuffers () failed during destructor call

As Qt users know, using any OpenGL extension can be quite annoying. The way I worked was to extend the QGLFunctions class as follows:

class Object3D : protected QGLFunctions{ ... } 

In order for Object3D to function correctly so that it can call functions such as glGenBuffer (), etc., you need to call

 initializeGLFunctions(glWidget->context()); 

AFTER QGLWidget was created, otherwise it just crashes the application when it uses any extension functions. Although I can finally call "glGenBuffer ()" and others throughout the existence of Object3D, it seems to break down into an Object3D () call that contains a call to "glDeleteBuffer ()". I am sure that this particular call causes application crashes.

Does anyone know how to solve this problem? I suspect this is because the QGLWidget is deleted first before Object3D, so the QGLWidget context is missing. If so, how can I make sure that QGLWidget is deleted last, since QGLWidget is added to QMainWindow, which simply removes its children in the order in which they are added?

+4
source share
1 answer

The general rule is that if you cannot guarantee that the OpenGL RAII object will be destroyed while the context is still around, then do not transfer OpenGL objects inside C ++ RAII classes. Manage the lifetime of OpenGL objects in other ways.

This is your code (which you neglected to show us); only you can decide where and how to manage class destruction. You need some kind of system to manage your objects, which ensures that things will be destroyed (and created) in the correct order.

+2
source

Source: https://habr.com/ru/post/1445407/


All Articles