From 6202a531530f8b910a5ebdc4de6dac903c947c25 Mon Sep 17 00:00:00 2001 From: chrisnch <108147436+chrisnch@users.noreply.github.com> Date: Sat, 22 Aug 2026 08:13:56 +0100 Subject: [PATCH] Fix GameSir rumble session teardown threading --- VoidLink/Input/GameSirG8MFiRumble.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/VoidLink/Input/GameSirG8MFiRumble.m b/VoidLink/Input/GameSirG8MFiRumble.m index 5e7b760e..6fc1f5ee 100644 --- a/VoidLink/Input/GameSirG8MFiRumble.m +++ b/VoidLink/Input/GameSirG8MFiRumble.m @@ -44,10 +44,10 @@ static NSString *const GameSirG8MFiModel = @"G8+ MFi"; - (void)dealloc { [NSNotificationCenter.defaultCenter removeObserver:self]; + NSAssert(NSThread.isMainThread || _session == nil, @"Active GameSir sessions must be closed on the main thread before deallocation"); if (NSThread.isMainThread) { - [self writeStopPacketBestEffort]; + [self stopAndCloseOnMainThread]; } - [self closeSession]; } - (void)applicationWillResignActive:(NSNotification *)notification { @@ -224,6 +224,7 @@ static NSString *const GameSirG8MFiModel = @"G8+ MFi"; } - (void)closeSession { + NSAssert(NSThread.isMainThread, @"GameSir sessions must be closed on the main thread"); if (_session != nil) { [_session.inputStream close]; [_session.outputStream close]; @@ -241,11 +242,17 @@ static NSString *const GameSirG8MFiModel = @"G8+ MFi"; } - (void)stopAndCloseOnMainThread { + NSAssert(NSThread.isMainThread, @"GameSir sessions must be stopped on the main thread"); [self writeStopPacketBestEffort]; [self closeSession]; } - (void)stopAndClose { + if (NSThread.isMainThread) { + [self stopAndCloseOnMainThread]; + return; + } + dispatch_async(dispatch_get_main_queue(), ^{ [self stopAndCloseOnMainThread]; });