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.
This commit is contained in:
Vadim Zeitlin
2021-05-22 16:23:53 +01:00
parent a352dee1f1
commit 880c50bade

View File

@@ -3426,9 +3426,11 @@ static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
void wxWindowBase::NotifyCaptureLost() void wxWindowBase::NotifyCaptureLost()
{ {
// don't do anything if capture lost was expected, i.e. resulted from // don't do anything if capture lost was expected, i.e. resulted from
// a wx call to ReleaseMouse or CaptureMouse: // a wx call to ReleaseMouse or CaptureMouse (but note that we must not
wxRecursionGuard guard(wxMouseCapture::changing); // change the "changing" flag here as the user code is expected to call
if ( guard.IsInside() ) // ReleaseMouse() from its wxMouseCaptureLostEvent handler and this
// shouldn't assert because the capture is already "changing")
if ( wxMouseCapture::changing )
return; return;
// if the capture was lost unexpectedly, notify every window that has // if the capture was lost unexpectedly, notify every window that has