From 8d30079033e1849f58379a59f02d0d53fe6cceec Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 16 Oct 2023 18:05:42 -0500 Subject: [PATCH] Prevent flooding the queue with motion events --- src/InputStream.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/InputStream.c b/src/InputStream.c index 9853d9f..ac20802 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -1444,6 +1444,13 @@ int LiSendControllerMotionEvent(uint8_t controllerNumber, uint8_t motionType, fl return LI_ERR_UNSUPPORTED; } + // Since these events can be sent incredibly frequently, let's avoid queuing more if + // we already have more than half of our max input queue full of other events. + if (LbqGetItemCount(&packetQueue) > MAX_QUEUED_INPUT_PACKETS / 2) { + Limelog("Dropping motion event due to high input queue length\n"); + return -1; + } + // Sunshine supports up to 16 controllers controllerNumber %= MAX_GAMEPADS;