From f4b937adf8d8ff853c8e72726069092ebf4fc54e Mon Sep 17 00:00:00 2001
From: Katharine Chui <[EMAIL REDACTED]>
Date: Thu, 8 Jan 2026 22:36:37 +0100
Subject: [PATCH] haptic hidapi: maintain effects array for external checking
(cherry picked from commit 2bb463921fbc4e45c2bf07a80be6978233c8ad9e)
---
src/haptic/hidapi/SDL_hidapihaptic.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/haptic/hidapi/SDL_hidapihaptic.c b/src/haptic/hidapi/SDL_hidapihaptic.c
index c3abc862e8627..fbcbd0f0cf335 100644
--- a/src/haptic/hidapi/SDL_hidapihaptic.c
+++ b/src/haptic/hidapi/SDL_hidapihaptic.c
@@ -144,6 +144,14 @@ bool SDL_HIDAPI_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystic
haptic->nplaying = device->driver->NumEffectsPlaying(device);
haptic->supported = device->driver->GetFeatures(device);
haptic->naxes = device->driver->NumAxes(device);
+ haptic->neffects = device->driver->NumEffects(device);
+ haptic->effects = (struct haptic_effect *)SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ device->driver->Close(device);
+ SDL_free(device);
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects);
// outside of SYS_HAPTIC
haptic->instance_id = 255;
@@ -215,6 +223,7 @@ void SDL_HIDAPI_HapticClose(SDL_Haptic *haptic)
SDL_free(device->ctx);
SDL_free(device);
+ SDL_free(haptic->effects);
SDL_free(cur);
SDL_UnlockMutex(haptic_list_mutex);
return;
@@ -238,7 +247,11 @@ void SDL_HIDAPI_HapticQuit(void)
SDL_HapticEffectID SDL_HIDAPI_HapticNewEffect(SDL_Haptic *haptic, const SDL_HapticEffect *base)
{
SDL_HIDAPI_HapticDevice *device = (SDL_HIDAPI_HapticDevice *)haptic->hwdata;
- return device->driver->CreateEffect(device, base);
+ SDL_HapticEffectID new_id = device->driver->CreateEffect(device, base);
+ if (new_id >= 0){
+ haptic->effects[new_id].effect = *base;
+ }
+ return new_id;
}
bool SDL_HIDAPI_HapticUpdateEffect(SDL_Haptic *haptic, SDL_HapticEffectID id, const SDL_HapticEffect *data)