From 850fe390ca6173f05cae6a0de4f3cd1ced44b5ab Mon Sep 17 00:00:00 2001 From: Dan Leehr Date: Mon, 23 Nov 2020 17:00:11 -0500 Subject: [PATCH] Fixes FLAC playback crash on Apple Silicon - Avoid creating an NSDictionary with NULL context object (https://github.com/kode54/Cog/blob/master/Audio/Chain/InputNode.m#L81 passes NULL as context, so this must be handled in NSDictionary creation - When calling addObserver, downgrade options from NSNumber * to NSKeyValueObservingOptions (aka NSUInteger) Not sure why this would be specific to Apple Silicon... --- Audio/CogPluginMulti.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Audio/CogPluginMulti.m b/Audio/CogPluginMulti.m index 7efe2f63b..f4ad98cb5 100644 --- a/Audio/CogPluginMulti.m +++ b/Audio/CogPluginMulti.m @@ -78,7 +78,10 @@ NSArray * sortClassesByPriority(NSArray * theClasses) Class decoder = NSClassFromString(classString); theDecoder = [[decoder alloc] init]; for (NSDictionary *obsItem in cachedObservers) { - [theDecoder addObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"] options:[obsItem objectForKey:@"options"] context:(__bridge void *)([obsItem objectForKey:@"context"])]; + [theDecoder addObserver:[obsItem objectForKey:@"observer"] + forKeyPath:[obsItem objectForKey:@"keyPath"] + options:[[obsItem objectForKey:@"options"] unsignedIntegerValue] + context:(__bridge void *)([obsItem objectForKey:@"context"])]; } if ([theDecoder open:source]) return YES; @@ -118,7 +121,11 @@ NSArray * sortClassesByPriority(NSArray * theClasses) /* By the current design, the core adds its observers to decoders before they are opened */ - (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context { - [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", options, @"options", context, @"context", nil]]; + if(context != nil) { + [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", context, @"context", nil]]; + } else { + [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", nil]]; + } } /* And this is currently called after the decoder is closed */