From 940188b2581b897f85678254569c1780c83e87a0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 2 Nov 2026 14:32:46 -0800
Subject: [PATCH] Added a deadlock warning about the GIP chatpad code
I don't think this ends up being an issue in practice, but I outlined how it should be fixed in case it bites someone.
---
src/joystick/hidapi/SDL_hidapi_gip.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/joystick/hidapi/SDL_hidapi_gip.c b/src/joystick/hidapi/SDL_hidapi_gip.c
index ba04919d53250..e095cce803934 100644
--- a/src/joystick/hidapi/SDL_hidapi_gip.c
+++ b/src/joystick/hidapi/SDL_hidapi_gip.c
@@ -1851,6 +1851,12 @@ static bool GIP_HandleCommandHidReport(
const Uint8 *bytes,
int num_bytes)
{
+ // WARNING: This function is called while the joystick lock is held and sending keyboard
+ // events will take the event lock. This will deadlock any other code that calls
+ // into SDL joystick functions while the event lock is held, such as from an event
+ // watcher. The fix is to queue the keyboard events here the same way we queue
+ // joystick events, if this ends up being a problem in practice.
+
Uint64 timestamp = SDL_GetTicksNS();
// SDL doesn't have HID descriptor parsing, so we have to hardcode for the Chatpad descriptor instead.
// I don't know of any other devices that emit HID reports, so this should be safe.