From 41f96866eeaa2d26c203c50401367db85b3eb5e9 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 21 Dec 2021 17:19:59 +0100 Subject: [PATCH] Windows: Don't crash in mouse handling when QApplication is recreated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We store the primary pointing device in a static variable to avoid the lookup for each mouse event. However, when QApplication is destroyed, then the device is destroyed, and the pointer needs to be reset so that QApplication can be created again by the same process without the first mouse event crashing the program. Use QPointer to prevent the pointer from becoming dangling. Fixes: QTBUG-99319 Pick-to: 6.2 6.3 Change-Id: Ie534c5eee48afb83e3a4adf70fc6cb4a2c310a7a Reviewed-by: Tor Arne Vestbø Reviewed-by: Friedemann Kleint Reviewed-by: André de la Rocha --- src/plugins/platforms/windows/qwindowsmousehandler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 9fc04da245..b052dc53e8 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -130,7 +130,9 @@ QWindowsMouseHandler::QWindowsMouseHandler() = default; const QPointingDevice *QWindowsMouseHandler::primaryMouse() { - static const auto result = QPointingDevice::primaryPointingDevice(); + static QPointer result; + if (!result) + result = QPointingDevice::primaryPointingDevice(); return result; }