From f4435d2d5cddc763ac9fb3d0b1b97e551ea463e1 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 20 Mar 2018 23:27:36 +0100 Subject: offscreen: Check that native interface is valid before using it If the offscreen platform plugin is used on Windows then it can end up crashing since there is no native interface. This prevents a crash from occurring when these functions are called. Change-Id: I526fc0703771fa5f85b26d182ad3b15ef1a3ada5 Reviewed-by: Friedemann Kleint --- src/plugins/styles/windowsvista/qwindowsxpstyle.cpp | 3 ++- src/widgets/kernel/qapplication_p.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index ff27cab98a..733b3a9e9c 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -122,7 +122,8 @@ static inline HDC hdcForWidgetBackingStore(const QWidget *widget) { if (QBackingStore *backingStore = backingStoreForWidget(widget)) { QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - return static_cast(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore)); + if (nativeInterface) + return static_cast(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore)); } return 0; } diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 9983cc7d9e..019fad3fc3 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -242,7 +242,7 @@ public: static HWND getHWNDForWidget(const QWidget *widget) { if (QWindow *window = windowForWidget(widget)) - if (window->handle()) + if (window->handle() && QGuiApplication::platformNativeInterface()) return static_cast (QGuiApplication::platformNativeInterface()-> nativeResourceForWindow(QByteArrayLiteral("handle"), window)); return 0; -- cgit v1.2.3