From 9618fb7262b1b23ef5420ee83aa3b6b697eedc3e Mon Sep 17 00:00:00 2001 From: Louai Al-Khanji Date: Fri, 19 Sep 2014 12:39:02 +0300 Subject: [PATCH] EGLFS: Fix plugin destruction The proper init/destruction order is as follows: QEglFsHooks::platformInit() eglInitialize() eglTerminate() QEglFsHooks::platformDestroy() Prior to this patch platformDestroy() was called before eglTerminate(), leading to a crash on some platforms. Additionally we need to destroy the native windows before deleting the screen, otherwise the QEglFSWindow destructor ends up calling into the deallocated screen. Change-Id: Id08ccbac9bb44a778bcf1a55f73c0057e0a7b3af Reviewed-by: Laszlo Agocs --- .../eglconvenience/qeglplatformintegration.cpp | 11 +++++++++++ .../eglconvenience/qeglplatformintegration_p.h | 1 + src/plugins/platforms/eglfs/qeglfsintegration.cpp | 10 +++++----- src/plugins/platforms/eglfs/qeglfsintegration.h | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/platformsupport/eglconvenience/qeglplatformintegration.cpp b/src/platformsupport/eglconvenience/qeglplatformintegration.cpp index b8205dc575..a6207cf402 100644 --- a/src/platformsupport/eglconvenience/qeglplatformintegration.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformintegration.cpp @@ -95,9 +95,15 @@ QEGLPlatformIntegration::QEGLPlatformIntegration() QEGLPlatformIntegration::~QEGLPlatformIntegration() { + foreach (QWindow *w, qGuiApp->topLevelWindows()) + w->destroy(); + delete m_screen; + if (m_display != EGL_NO_DISPLAY) eglTerminate(m_display); + + destroy(); } void QEGLPlatformIntegration::initialize() @@ -118,6 +124,11 @@ void QEGLPlatformIntegration::initialize() m_vtHandler.reset(new QFbVtHandler); } +void QEGLPlatformIntegration::destroy() +{ + +} + QAbstractEventDispatcher *QEGLPlatformIntegration::createEventDispatcher() const { return createUnixEventDispatcher(); diff --git a/src/platformsupport/eglconvenience/qeglplatformintegration_p.h b/src/platformsupport/eglconvenience/qeglplatformintegration_p.h index 4d7adce309..11977db78b 100644 --- a/src/platformsupport/eglconvenience/qeglplatformintegration_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformintegration_p.h @@ -65,6 +65,7 @@ public: ~QEGLPlatformIntegration(); void initialize() Q_DECL_OVERRIDE; + virtual void destroy(); QEGLPlatformScreen *screen() const { return m_screen; } EGLDisplay display() const { return m_display; } diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/qeglfsintegration.cpp index 12b8fabdfc..16d8c50291 100644 --- a/src/plugins/platforms/eglfs/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/qeglfsintegration.cpp @@ -67,11 +67,6 @@ QEglFSIntegration::QEglFSIntegration() initResources(); } -QEglFSIntegration::~QEglFSIntegration() -{ - QEglFSHooks::hooks()->platformDestroy(); -} - bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const { // We assume that devices will have more and not less capabilities @@ -91,6 +86,11 @@ void QEglFSIntegration::initialize() createInputHandlers(); } +void QEglFSIntegration::destroy() +{ + QEglFSHooks::hooks()->platformDestroy(); +} + EGLNativeDisplayType QEglFSIntegration::nativeDisplay() const { return QEglFSHooks::hooks()->platformDisplay(); diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.h b/src/plugins/platforms/eglfs/qeglfsintegration.h index d612a270f2..59aabebb7a 100644 --- a/src/plugins/platforms/eglfs/qeglfsintegration.h +++ b/src/plugins/platforms/eglfs/qeglfsintegration.h @@ -44,9 +44,9 @@ class QEglFSIntegration : public QEGLPlatformIntegration { public: QEglFSIntegration(); - ~QEglFSIntegration(); void initialize() Q_DECL_OVERRIDE; + void destroy() Q_DECL_OVERRIDE; bool hasCapability(QPlatformIntegration::Capability cap) const Q_DECL_OVERRIDE; QVariant styleHint(QPlatformIntegration::StyleHint hint) const Q_DECL_OVERRIDE;