Segfault when the exiting the application under platform eglfs

If you run an application under eglfs, it falls with segfault on the
exit. For example, examples/gui/analogclock,
examples/widgets/widgets/analogclock, examples/opengl/cube,
examples/opengl/qopenglwidget, etc. (I have added the function
keyPressEvent to exit  by qApp->quit(), if needed).
It isn't appear in applications using QQuickView or QGLWindow.
This is because QCoreApplication destructor, where the variable self = 0
(therefore, qGuiApp = 0), is called before than
QOpenGLVertexArrayObject::destroy(), where qGuiApp is accessed
(qGuiApp->thread()).

Task-number: QTBUG-73824
Change-Id: I1dc55d5e811bfe8a8ea2178752e8771f8644d356
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Elena Zaretskaya 2019-02-14 09:49:33 -05:00 committed by Laszlo Agocs
parent 49ef377349
commit ca991ee22d
3 changed files with 18 additions and 13 deletions

View File

@ -62,9 +62,6 @@ QEglFSScreen::QEglFSScreen(EGLDisplay dpy)
QEglFSScreen::~QEglFSScreen() QEglFSScreen::~QEglFSScreen()
{ {
delete m_cursor; delete m_cursor;
#ifndef QT_NO_OPENGL
QOpenGLCompositor::destroy();
#endif
} }
QRect QEglFSScreen::geometry() const QRect QEglFSScreen::geometry() const

View File

@ -62,6 +62,7 @@ QEglFSWindow::QEglFSWindow(QWindow *w)
: QPlatformWindow(w), : QPlatformWindow(w),
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
m_backingStore(0), m_backingStore(0),
m_rasterCompositingContext(0),
#endif #endif
m_raster(false), m_raster(false),
m_winId(0), m_winId(0),
@ -144,18 +145,18 @@ void QEglFSWindow::create()
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (isRaster()) { if (isRaster()) {
QOpenGLContext *context = new QOpenGLContext(QGuiApplication::instance()); m_rasterCompositingContext = new QOpenGLContext;
context->setShareContext(qt_gl_global_share_context()); m_rasterCompositingContext->setShareContext(qt_gl_global_share_context());
context->setFormat(m_format); m_rasterCompositingContext->setFormat(m_format);
context->setScreen(window()->screen()); m_rasterCompositingContext->setScreen(window()->screen());
if (Q_UNLIKELY(!context->create())) if (Q_UNLIKELY(!m_rasterCompositingContext->create()))
qFatal("EGLFS: Failed to create compositing context"); qFatal("EGLFS: Failed to create compositing context");
compositor->setTarget(context, window(), screen->rawGeometry()); compositor->setTarget(m_rasterCompositingContext, window(), screen->rawGeometry());
compositor->setRotation(qEnvironmentVariableIntValue("QT_QPA_EGLFS_ROTATION")); compositor->setRotation(qEnvironmentVariableIntValue("QT_QPA_EGLFS_ROTATION"));
// If there is a "root" window into which raster and QOpenGLWidget content is // If there is a "root" window into which raster and QOpenGLWidget content is
// composited, all other contexts must share with its context. // composited, all other contexts must share with its context.
if (!qt_gl_global_share_context()) { if (!qt_gl_global_share_context()) {
qt_gl_set_global_share_context(context); qt_gl_set_global_share_context(m_rasterCompositingContext);
// What we set up here is in effect equivalent to the application setting // What we set up here is in effect equivalent to the application setting
// AA_ShareOpenGLContexts. Set the attribute to be fully consistent. // AA_ShareOpenGLContexts. Set the attribute to be fully consistent.
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
@ -166,6 +167,10 @@ void QEglFSWindow::create()
void QEglFSWindow::destroy() void QEglFSWindow::destroy()
{ {
#ifndef QT_NO_OPENGL
QOpenGLCompositor::instance()->removeWindow(this);
#endif
QEglFSScreen *screen = this->screen(); QEglFSScreen *screen = this->screen();
if (m_flags.testFlag(HasNativeWindow)) { if (m_flags.testFlag(HasNativeWindow)) {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
@ -177,12 +182,14 @@ void QEglFSWindow::destroy()
screen->setPrimarySurface(EGL_NO_SURFACE); screen->setPrimarySurface(EGL_NO_SURFACE);
invalidateSurface(); invalidateSurface();
#ifndef QT_NO_OPENGL
QOpenGLCompositor::destroy();
delete m_rasterCompositingContext;
#endif
} }
m_flags = 0; m_flags = 0;
#ifndef QT_NO_OPENGL
QOpenGLCompositor::instance()->removeWindow(this);
#endif
} }
void QEglFSWindow::invalidateSurface() void QEglFSWindow::invalidateSurface()

View File

@ -116,6 +116,7 @@ public:
protected: protected:
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
QOpenGLCompositorBackingStore *m_backingStore; QOpenGLCompositorBackingStore *m_backingStore;
QOpenGLContext *m_rasterCompositingContext;
#endif #endif
bool m_raster; bool m_raster;
WId m_winId; WId m_winId;