Unsolved Segfault when connect cleanup OpenGL function to signal QOpenGLContext::aboutToBeDestroyed
-
Hi I am using the QOpenGLWidget of Qt 5.9.2 on Ubuntu16.04. Using the following connect() to clean up OpenGL buffer objects but get segment fault when destroy buffer objects. So I ended up putting cleanup() in the destructor. I remembered this signal ::aboutToBeDestroyed is recommended to do cleanup to the destructor but why it does not work now.
Does not work:
connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &MainOpenGLWidget::cleanup);
void MainOpenGLWidget::cleanup() { makeCurrent(); if (m_program) { delete m_program; m_program = 0; } if (m_vboPos.isCreated()) m_vboPos.destroy(); // Segfault here if (m_vboCol.isCreated()) m_vboCol.destroy(); if (m_vao.isCreated()) m_vao.destroy(); doneCurrent(); }
This works:
MainOpenGLWidget::~MainOpenGLWidget() { cleanup(); }