mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-05 22:30:29 +00:00
testcontroller: free/allocate touchpads only when needed
This commit is contained in:
parent
d4fa4b4634
commit
d3d8e16e67
1 changed files with 7 additions and 3 deletions
|
|
@ -706,6 +706,7 @@ static void FreeTouchpads(GamepadImage *ctx)
|
|||
void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
|
||||
{
|
||||
int i;
|
||||
int num_touchpads;
|
||||
|
||||
if (!ctx) {
|
||||
return;
|
||||
|
|
@ -763,9 +764,12 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
|
|||
ctx->connection_state = SDL_GetGamepadConnectionState(gamepad);
|
||||
ctx->battery_state = SDL_GetGamepadPowerInfo(gamepad, &ctx->battery_percent);
|
||||
|
||||
FreeTouchpads(ctx);
|
||||
ctx->num_touchpads = SDL_GetNumGamepadTouchpads(gamepad);
|
||||
ctx->num_touchpads = SDL_min(ctx->num_touchpads, MAX_TOUCHPADS);
|
||||
num_touchpads = SDL_GetNumGamepadTouchpads(gamepad);
|
||||
num_touchpads = SDL_min(num_touchpads, MAX_TOUCHPADS);
|
||||
if (num_touchpads != ctx->num_touchpads) {
|
||||
FreeTouchpads(ctx);
|
||||
ctx->num_touchpads = num_touchpads;
|
||||
}
|
||||
if (ctx->num_touchpads > 0) {
|
||||
ctx->touchpads = (GamepadTouchpad *)SDL_malloc(sizeof(*ctx->touchpads) * ctx->num_touchpads);
|
||||
if (ctx->touchpads) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue