From 880c50bade02f4ca3fb4a0532c97f2477e6794ab Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 May 2021 16:23:53 +0100 Subject: [PATCH] Avoid bogus assert failures when releasing mouse capture Calling ReleaseMouse() from wxEVT_MOUSE_CAPTURE_LOST handler could result in bogus asserts about ReleaseMouse() reentrancy because the function generating "capture lost" events in wx itself wrongly set the wxMouseCapture::changing flag, instead of just examining it, as it was supposed to do. This corrects a problem introduced back in b0ad1918b9 (No changes, just use wxRecursionGuard instead of manual boolean flag., 2013-08-18) which, contrary to the commit message, did change the behaviour by replacing a simple test with the use of wxRecursionGuard here. --- src/common/wincmn.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index c43f6f813d..5771b95c6a 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -3426,9 +3426,11 @@ static void DoNotifyWindowAboutCaptureLost(wxWindow *win) void wxWindowBase::NotifyCaptureLost() { // don't do anything if capture lost was expected, i.e. resulted from - // a wx call to ReleaseMouse or CaptureMouse: - wxRecursionGuard guard(wxMouseCapture::changing); - if ( guard.IsInside() ) + // a wx call to ReleaseMouse or CaptureMouse (but note that we must not + // change the "changing" flag here as the user code is expected to call + // ReleaseMouse() from its wxMouseCaptureLostEvent handler and this + // shouldn't assert because the capture is already "changing") + if ( wxMouseCapture::changing ) return; // if the capture was lost unexpectedly, notify every window that has