gameprogcpp/code

Serious bug in mouse button detection

Closed this issue · 1 comments

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);
}

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.