Crash Fix: Only selectively register observer
This affects User Defaults, but only has any effect on ChunkLists which are being used for conversion, and only if they're processing DSD source material. Thus, the observer should only be added on the one stream that is converting DSD, and should definitely be removed when the object is deallocated. This fixes a serious crash bug that mostly appears to only affect Intel Macs, and has no major side effects on Apple Silicon that I can tell. It's a good thing I still own an Intel Mac or two to test on, even if they are both trapped on older releases of macOS. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
fdd0244067
commit
9aaf6d1c2d
2 changed files with 22 additions and 3 deletions
|
@ -39,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
int dsd2pcmLatency;
|
||||
#endif
|
||||
|
||||
BOOL observersRegistered;
|
||||
BOOL halveDSDVolume;
|
||||
|
||||
void *hdcd_decoder;
|
||||
|
|
|
@ -399,19 +399,36 @@ static void convert_be_to_le(uint8_t *buffer, size_t bitsPerSample, size_t bytes
|
|||
dsd2pcmLatency = 0;
|
||||
#endif
|
||||
|
||||
halveDSDVolume = NO;
|
||||
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.halveDSDVolume" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:kChunkListContext];
|
||||
observersRegistered = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addObservers {
|
||||
if(!observersRegistered) {
|
||||
halveDSDVolume = NO;
|
||||
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.halveDSDVolume" options:(NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew) context:kChunkListContext];
|
||||
|
||||
observersRegistered = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeObservers {
|
||||
if(observersRegistered) {
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.halveDSDVolume" context:kChunkListContext];
|
||||
|
||||
observersRegistered = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
stopping = YES;
|
||||
while(inAdder || inRemover || inPeeker || inMerger || inConverter) {
|
||||
usleep(500);
|
||||
}
|
||||
[self removeObservers];
|
||||
if(hdcd_decoder) {
|
||||
free(hdcd_decoder);
|
||||
hdcd_decoder = NULL;
|
||||
|
@ -786,6 +803,7 @@ static void convert_be_to_le(uint8_t *buffer, size_t bitsPerSample, size_t bytes
|
|||
isFloat = YES;
|
||||
inputBuffer = &tempData[buffer_adder];
|
||||
inputChanged = YES;
|
||||
[self addObservers];
|
||||
#if DSD_DECIMATE
|
||||
if(halveDSDVolume) {
|
||||
float scaleFactor = 2.0f;
|
||||
|
|
Loading…
Reference in a new issue