Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.12.2
-
None
Description
My Qt desktop application crashed in the line of "Q_D(const QOpenGLContext)" come from the file qopenglcontext.cpp as below. I found that "this pointer" is "0x00000000 ", that means QOpenGLContext is null:
QOpenGLFunctions *QOpenGLContext::functions() const { Q_D(const QOpenGLContext); // crash here !!!!!!!!!!! if (!d->functions) const_cast<QOpenGLFunctions *&>(d->functions) = new QOpenGLExtensions(QOpenGLContext::currentContext()); return d->functions; }
When I check the crash stack by dump file, find that the last stack frame called the function "QOpenGLContext::functions() come from the file qopenglwidget.cpp" is null as below:
void QOpenGLWidgetPrivate::invalidateFbo() { ///////////// here QOpenGLContext::currentContext() is null QOpenGLExtensions *f = static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions()); ///////////// here QOpenGLContext::currentContext() is null if (f->hasOpenGLExtension(QOpenGLExtensions::DiscardFramebuffer)) { const int gl_color_attachment0 = 0x8CE0; // GL_COLOR_ATTACHMENT0 const int gl_depth_attachment = 0x8D00; // GL_DEPTH_ATTACHMENT const int gl_stencil_attachment = 0x8D20; // GL_STENCIL_ATTACHMENT
Then, I check the interior of the function "QOpenGLContext::currentContext() come from openglcontext.cpp" as below:
QOpenGLContext* QOpenGLContext::currentContext() { //////////// HERE qwindow_context_storage()->localData() return null QGuiGLThreadContext *threadContext = qwindow_context_storage()->localData(); //////////// HERE qwindow_context_storage()->localData() return null if (threadContext) { return threadContext->context; } return 0; }
So, When QOpenGLContext::currentContext() will return null?
And, what are the possible ways I can avoid null?