Use OpenGL commands only in paintGL() #261
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I compiled Candle from source on MacOS High Sierra and experienced a lot of crashes when launching the application. Upon debugging the issue I found that an assert inside glClearColor() within paintevent() triggered. The assert was checking whether OpenGL had been initialized. Indeed, initializeGL() was NOT called before the paintEvent appeared.
I read the documentation on QtOpenGL and the way I understand it is, that OpenGL commands have to be put inside paintGL(), which is called by the paintEvent() handler of the base class, which also takes care of properly calling initializeGL().
So I removed paintEvent() and renamed it in non-GLES code to paintGL(). That fixed the issue. OpenGL is now properly initialized and drawing works. (Sometimes Candle was able to launch without that change, but things were not drawn correctly. Maybe this fixes also some of the other reported drawing-related bugs.)
I don't really understand why there are OpenGL calls being issued in paintEvent(), but I believe this is wrong.
I'm also not sure why GLWidget inherits from QOpenGLWidget with GLES and from QGLWidget otherwise. My understanding is that QGLWidget is for backwards-compatibility with older Qt-Versions and QOpenGLWidget is its modern substitute. So I think QOpenGLWidget can always be used.
I'm new to the Candle code base and I'm happy to discuss this issue and make further fixes, if necessary.