mirror of
https://gitea.tendokyu.moe/Hay1tsme/segatools.git
synced 2026-05-06 13:25:35 -05:00
## Overview This PR addresses the severe memory leak and performance issues observed in `mai2`, while also introducing improvements to the touch emulation logic. ## Root Cause Analysis As discussed previously, the root cause of the `mai2` memory leak is not a global `segatools` buffer bug. Instead, the game aggressively spams overlapped empty reads specifically on the `LED 15070` UART. On real hardware, the serial driver naturally throttles this. Under emulation, without a throttle, it hits approximately **260kHz of empty async reads**, which causes the memory usage to explode. ## The Fix Instead of introducing complex locking mechanisms and condition variables globally in `uart.c`, this PR applies a targeted fix: * Added a local `Sleep(1)` directly in `common/board/led15070.c` to rate-limit empty reads on the LED path. * Because this is isolated to LED communications, it completely resolves the memory leak without introducing any lag, livelocks, or overhead to other critical inputs. ## Additional Changes in this PR Alongside the memory leak fix, this PR includes a few touch-related improvements (as touch emulation was reviewed during the debugging process): * Enhanced touch input handling and improved auto-scan state management. * Implemented IOCTL handling for touch input to properly manage communication status. ## Testing * **mai2:** Tested successfully on multiple machines. The memory leak is completely gone, and the game runs smoothly. * **chusan:** Tested to ensure no regressions. Sliders and inputs work flawlessly without the lag. Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/101 Co-authored-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe> Co-committed-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe> |
||
|---|---|---|
| .. | ||
| aime-dll.c | ||
| aime-dll.h | ||
| config.c | ||
| config.h | ||
| elo-cmd.h | ||
| elo-frame.c | ||
| elo-frame.h | ||
| ffb.c | ||
| ffb.h | ||
| guid.c | ||
| guid.h | ||
| io3.c | ||
| io3.h | ||
| io4.c | ||
| io4.h | ||
| led15070-cmd.h | ||
| led15070-frame.c | ||
| led15070-frame.h | ||
| led15070.c | ||
| led15070.h | ||
| led15093-cmd.h | ||
| led15093-frame.c | ||
| led15093-frame.h | ||
| led15093.c | ||
| led15093.h | ||
| meson.build | ||
| sg-cmd.c | ||
| sg-cmd.h | ||
| sg-frame.c | ||
| sg-frame.h | ||
| sg-led-cmd.h | ||
| sg-led.c | ||
| sg-led.h | ||
| sg-nfc-cmd.h | ||
| sg-nfc.c | ||
| sg-nfc.h | ||
| sg-reader-queue.c | ||
| sg-reader-queue.h | ||
| sg-reader.c | ||
| sg-reader.h | ||
| slider-cmd.h | ||
| slider-frame.c | ||
| slider-frame.h | ||
| vfd-cmd.h | ||
| vfd-frame.c | ||
| vfd-frame.h | ||
| vfd.c | ||
| vfd.h | ||