From 81777ea3b943ac1b562ae170e5e7e1ec2eb7f7e3 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Mon, 21 Dec 2020 18:49:40 +0000 Subject: [PATCH] Bug 1465513: Call IDropTargetHelper::DragLeave before IDropTargetHelper::DragEnter. r=dmajor,NeilDeakin This is an attempt clean up any stale information to try and solve crashes later in the drag in nsNativeDragTarget::DragOver. Differential Revision: https://phabricator.services.mozilla.com/D100124 --- widget/windows/nsNativeDragTarget.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/widget/windows/nsNativeDragTarget.cpp b/widget/windows/nsNativeDragTarget.cpp index a8909e47915d..cdb53dfde3c6 100644 --- a/widget/windows/nsNativeDragTarget.cpp +++ b/widget/windows/nsNativeDragTarget.cpp @@ -237,6 +237,12 @@ nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState, // Drag and drop image helper if (GetDropTargetHelper()) { + // We get a lot of crashes (often uncaught by our handler) later on during + // DragOver calls, see bug 1465513. It looks like this might be because + // we're not cleaning up previous drags fully and now released resources get + // used. Calling IDropTargetHelper::DragLeave before DragEnter seems to fix + // this for at least one reproduction of this crash. + GetDropTargetHelper()->DragLeave(); POINT pt = {ptl.x, ptl.y}; GetDropTargetHelper()->DragEnter(mHWnd, pIDataSource, &pt, *pdwEffect); } @@ -313,6 +319,8 @@ nsNativeDragTarget::DragOver(DWORD grfKeyState, POINTL ptl, LPDWORD pdwEffect) { // Drag and drop image helper if (GetDropTargetHelper()) { if (dragImageChanged) { + // See comment in nsNativeDragTarget::DragEnter. + GetDropTargetHelper()->DragLeave(); // The drop helper only updates the image during DragEnter, so emulate // a DragEnter if the image was changed. POINT pt = {ptl.x, ptl.y};