Skip to content

Commit

Permalink
Windows: Don't crash in mouse handling when QApplication is recreated
Browse files Browse the repository at this point in the history
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ø <[email protected]>
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: André de la Rocha <[email protected]>
  • Loading branch information
vohi committed Dec 22, 2021
1 parent 7bd243b commit 41f9686
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugins/platforms/windows/qwindowsmousehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ QWindowsMouseHandler::QWindowsMouseHandler() = default;

const QPointingDevice *QWindowsMouseHandler::primaryMouse()
{
static const auto result = QPointingDevice::primaryPointingDevice();
static QPointer<const QPointingDevice> result;
if (!result)
result = QPointingDevice::primaryPointingDevice();
return result;
}

Expand Down

0 comments on commit 41f9686

Please sign in to comment.