Fixed random behavior occurring due to passing 0xFFFF into SDL_GameControllerGetButton. May have shown up as unexpected button presses, or something far worse like a segfault. Source comments explain a little better.
This commit is contained in:
parent
bb27c041ea
commit
833649621a
|
@ -51,11 +51,26 @@ DTestButtonGC(ButtConfig *bc)
|
||||||
for(x = 0; x < bc->NumC; x++)
|
for(x = 0; x < bc->NumC; x++)
|
||||||
{
|
{
|
||||||
gc = s_GameCtrls[bc->DeviceNum[x]];
|
gc = s_GameCtrls[bc->DeviceNum[x]];
|
||||||
if( SDL_GameControllerGetButton(gc, (SDL_GameControllerButton) bc->ButtonNum[x]) )
|
/***
|
||||||
|
* ButtConfig->ButtonNum is a uint16. SDL_CONTROLLER_BUTTON_INVALID,
|
||||||
|
* used to mark unused button mappings (since 0 is a valid btn too), is
|
||||||
|
* defined as -1, but this turns into 0xFFFF, which doesn't cast back to
|
||||||
|
* SDL_GameControllerButton type.
|
||||||
|
*
|
||||||
|
* Without bounds-checking, if 0xFFFF is passed into GetButton, it results
|
||||||
|
* in random behavior since GetButton lacks internal bounds checking. The
|
||||||
|
* "fun" symptom that lead to discovery of this issue was that "select"
|
||||||
|
* would also press the turbo A and turbo B buttons.
|
||||||
|
*/
|
||||||
|
if( bc->ButtonNum[x] < SDL_CONTROLLER_BUTTON_MAX )
|
||||||
{
|
{
|
||||||
//printf("GC %d btn '%s'=down\n", bc->DeviceNum[x],
|
/** Check to see if this button is depressed */
|
||||||
// SDL_GameControllerGetStringForButton( (SDL_GameControllerButton) bc->ButtonNum[x]));
|
if( SDL_GameControllerGetButton(gc, (SDL_GameControllerButton) bc->ButtonNum[x]) )
|
||||||
return 1;
|
{
|
||||||
|
//printf("GC %d btn '%s'=down\n", bc->DeviceNum[x],
|
||||||
|
// SDL_GameControllerGetStringForButton( (SDL_GameControllerButton) bc->ButtonNum[x]));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue