From 9c660b593a49f9852fc22e51e55065bab3d42ebf Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Mon, 21 Oct 2013 11:24:48 -0700 Subject: [PATCH] Whoops, fixed observer handling --- Audio/CogDecoderMulti.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Audio/CogDecoderMulti.m b/Audio/CogDecoderMulti.m index 4ccfeb1b8..4d55bc9a2 100644 --- a/Audio/CogDecoderMulti.m +++ b/Audio/CogDecoderMulti.m @@ -49,11 +49,17 @@ }]; theDecoders = sortedDecoders; theDecoder = nil; - cachedObservers = [[[NSMutableArray alloc] init] autorelease]; + cachedObservers = [[NSMutableArray alloc] init]; } return self; } +- (void)dealloc +{ + [cachedObservers release]; + [super dealloc]; +} + - (NSDictionary *)properties { if ( theDecoder != nil ) return [theDecoder properties]; @@ -97,6 +103,9 @@ { if ( theDecoder != nil ) { [theDecoder close]; + for (NSDictionary *obsItem in cachedObservers) { + [theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]]; + } [theDecoder release]; theDecoder = nil; } @@ -114,14 +123,14 @@ [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", options, @"options", context, @"context", nil]]; } +/* And this is currently called after the decoder is closed */ - (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath { - if ( theDecoder != nil ) - [theDecoder removeObserver:observer forKeyPath:keyPath]; for (NSDictionary *obsItem in cachedObservers) { if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) { [cachedObservers removeObject:obsItem]; + break; } } }