0
votes

I have a QGLWidget as the central widget of my QMainWindow. It initializes GL context and makes draw calls in its paintGl function. In my menubar from QMainWindow, I have an import file button which triggers a function that only runs if the QGLWidget is done with initializeGL function. This import file button call should transfer vertexes of a 3d object to GL buffers, which seems to work fine.

However, when QGLWidget calls its paint function, I receive a bad access error with following lines opened in debug mode :

Q_ASSERT(QOpenGLFunctions::isInitialized(d_ptr));
d_ptr->DrawArrays(mode, first, count);     //exc_bad_access

If I trigger my file importing function not from import file button in menu but directly from QGLWidget's initializeGl function, then everything is fine.

What might be the problem? Please let me know if you need further information.

1

1 Answers

0
votes

I found out that,

Each time paint function or initializeGL function runs they automatically call makeCurrent() function to make QGLWidget's gl contex current in the current thread. Even though QMainWindow runs in the same thread with the QGLWidget, bypassing QGLWidget class and therefore omitting makeCurrent()function resulted OpenGl functions in my "file import" function to run at different contexts(or null context) than QGLWidget.