Skip to content

Serious bug in mouse button detection #52

Closed

Description

@LeeTeng2001

Hello, first of all I really thank you for writing this book. When I was doing the camera part I noticed the weird behaviour of mouse detection in the InputSystem, turns out it's wrong to test equality for mouse button because valid result should be non-negative but doesn't guarantee 1.

bool MouseState::GetButtonValue(int button) const
{
	return (SDL_BUTTON(button) & mCurrButtons) == 1;  // Will not work!!!
}

The correct code should be

bool MouseState::GetButtonValue(int button) const
{
	return (SDL_BUTTON(button) & mCurrButtons);
}

Activity

  1. chalonverse commented on Apr 9, 2022

    @chalonverse
    Contributor

    This is a great find. Funny I missed that, but I probably didn't notice it since I always used GetButtonState instead of the GetButtonValue function, which would work correctly because of the tests against 0 instead of 1.

  2. added a commit that references this issue on Jul 14, 2022
  3. added a commit that references this issue on Feb 4, 2024
    ddcb472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions