Bug Fix: Unregister observer correctly

Only unregister it if it was actually registered.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-02-27 14:39:10 -08:00
parent 970f472436
commit 6f269dd689
2 changed files with 7 additions and 2 deletions

View file

@ -40,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
#endif
BOOL halveDSDVolume;
BOOL observersAdded;
void *hdcd_decoder;

View file

@ -402,6 +402,8 @@ static void convert_be_to_le(uint8_t *buffer, size_t bitsPerSample, size_t bytes
halveDSDVolume = NO;
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.halveDSDVolume" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:kChunkListContext];
observersAdded = YES;
}
return self;
@ -429,8 +431,10 @@ static void convert_be_to_le(uint8_t *buffer, size_t bitsPerSample, size_t bytes
if(tempData) {
free(tempData);
}
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.halveDSDVolume" context:kChunkListContext];
if(observersAdded) {
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.halveDSDVolume" context:kChunkListContext];
observersAdded = NO;
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {