Skip to content

Win32: SetCapture/ReleaseCapture Stale State #3724

Description

@jkeller51

Prerequisite Checklist

Describe your issue here

See:

// Capture the mouse in case the user wants to drag it outside
if ((wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2)) == 0)
{
// Only release the capture if we really have it
if (GetCapture() == m_handle)
ReleaseCapture();
}
else if (GetCapture() != m_handle)
{
// Set the capture to continue receiving mouse events
SetCapture(m_handle);
}

When the mouse is clicked in a window, it receives, among other things, a WM_MOUSEMOVE with some mouse key flags indicating the mouse buttons held. This causes SetCapture() to be called.

Capture is only released when the mouse is moved without a button held. This is not the same as releasing capture when the button is released! If the mouse does not move while the button is released, the window retains capture until the mouse moves. This seems to be a bug. If you are in an environment where someone else is waiting for capture to release on your window, the user has to physically move the mouse after releasing the button before the state is updated.

It seems the capture should actually be released in the LBUTTONUP, RBUTTONUP, ... handlers.

Your Environment

  • Windows 11
  • SFML 3.1 @ a91a7f6
  • MSVC
  • Special compiler / CMake flags: SFML_STATIC

Steps to reproduce

In any SFML-managed Win32 window, put logging breakpoints in the handler for WM_MOUSEMOVE, on SetCapture() and ReleaseCapture(). You will see that ReleaseCapture() is not called until the mouse moves.

Expected behavior

ReleaseCapture() should happen as soon as the mouse button is released, regardless of moving.

Actual behavior

ReleaseCapture() only happens when the mouse moves after the button is released.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Planned

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions