From 57f8c59b0a502fbfaf781555f46faacfbbecaa57 Mon Sep 17 00:00:00 2001 From: Sol Williams <7689429+solwllms@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:20:48 +0000 Subject: [PATCH] Fix crash when drag drop is cancelled/cleaned up before windows callback --- .../src/plugins/platforms/windows/qwindowsdrag.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/valve/qtbase/src/plugins/platforms/windows/qwindowsdrag.cpp b/valve/qtbase/src/plugins/platforms/windows/qwindowsdrag.cpp index ba049cf359..0c353cc814 100644 --- a/valve/qtbase/src/plugins/platforms/windows/qwindowsdrag.cpp +++ b/valve/qtbase/src/plugins/platforms/windows/qwindowsdrag.cpp @@ -429,7 +429,15 @@ QWindowsOleDropSource::GiveFeedback(DWORD dwEffect) const Qt::DropAction action = translateToQDragDropAction(dwEffect); m_drag->updateAction(action); - const qint64 currentCacheKey = m_drag->currentDrag()->dragCursor(action).cacheKey(); + // Sol: seeing it's possible currentDrag has been deleted by the time the win32 callback into here is called + const QDrag *drag = m_drag->currentDrag(); + if (!drag) { + QWindowsDrag *windowsDrag = QWindowsDrag::instance(); + windowsDrag->cancelDrag(); + return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS); + } + + const qint64 currentCacheKey = drag->dragCursor(action).cacheKey(); auto it = m_cursors.constFind(action); // If a custom drag cursor is set, check its cache key to detect changes. if (it == m_cursors.constEnd() || (currentCacheKey && currentCacheKey != it.value().cacheKey)) {