Fix GameSir rumble session teardown threading

This commit is contained in:
chrisnch committed 2026-08-22 08:13:56 +01:00
1 parent 84b6b22f75
commit 6202a53153
1 file changed
+9 -2
+9 -2
View File
@@ -44,10 +44,10 @@ static NSString *const GameSirG8MFiModel = @"G8+ MFi";
- (void)dealloc { - (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self]; [NSNotificationCenter.defaultCenter removeObserver:self];
NSAssert(NSThread.isMainThread || _session == nil, @"Active GameSir sessions must be closed on the main thread before deallocation");
if (NSThread.isMainThread) { if (NSThread.isMainThread) {
[self writeStopPacketBestEffort]; [self stopAndCloseOnMainThread];
} }
[self closeSession];
} }
- (void)applicationWillResignActive:(NSNotification *)notification { - (void)applicationWillResignActive:(NSNotification *)notification {
@@ -224,6 +224,7 @@ static NSString *const GameSirG8MFiModel = @"G8+ MFi";
} }
- (void)closeSession { - (void)closeSession {
NSAssert(NSThread.isMainThread, @"GameSir sessions must be closed on the main thread");
if (_session != nil) { if (_session != nil) {
[_session.inputStream close]; [_session.inputStream close];
[_session.outputStream close]; [_session.outputStream close];
@@ -241,11 +242,17 @@ static NSString *const GameSirG8MFiModel = @"G8+ MFi";
} }
- (void)stopAndCloseOnMainThread { - (void)stopAndCloseOnMainThread {
NSAssert(NSThread.isMainThread, @"GameSir sessions must be stopped on the main thread");
[self writeStopPacketBestEffort]; [self writeStopPacketBestEffort];
[self closeSession]; [self closeSession];
} }
- (void)stopAndClose { - (void)stopAndClose {
if (NSThread.isMainThread) {
[self stopAndCloseOnMainThread];
return;
}
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self stopAndCloseOnMainThread]; [self stopAndCloseOnMainThread];
}); });