Skip to content

Commit

Permalink
Bug Fix: Unregister observer correctly
Browse files Browse the repository at this point in the history
Only unregister it if it was actually registered.

Signed-off-by: Christopher Snowhill <[email protected]>
  • Loading branch information
kode54 committed Feb 27, 2025
1 parent bfa9660 commit 00d861e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Audio/Chain/ChunkList.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
#endif

BOOL halveDSDVolume;
BOOL observersAdded;

void *hdcd_decoder;

Expand Down
8 changes: 6 additions & 2 deletions Audio/Chain/ChunkList.m
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ - (id)initWithMaximumDuration:(double)duration {
halveDSDVolume = NO;

[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.halveDSDVolume" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:kChunkListContext];

observersAdded = YES;
}

return self;
Expand Down Expand Up @@ -429,8 +431,10 @@ - (void)dealloc {
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 {
Expand Down

0 comments on commit 00d861e

Please sign in to comment.