Re: another n00b question -- addObserver weirdness
Re: another n00b question -- addObserver weirdness
- Subject: Re: another n00b question -- addObserver weirdness
- From: Quincey Morris <email@hidden>
- Date: Tue, 11 Nov 2008 11:48:28 -0800
On Nov 11, 2008, at 10:35, John Zorko wrote:
2008-11-11 10:05:51.538 Magnatune[1382:20b] *** Terminating app due
to uncaught exception 'NSRangeException', reason: 'Cannot remove an
observer <MagnatuneAppDelegate 0x11d3b0> for the key path
"buffersEmpty" from <AudioStreamer 0x90fe00> because it is not
registered as an observer.'
The MagnatuneAppDelegate address (11d3b0) is the same, so i'm adding
observers to / removing observers from the same (and only)
instance. Why does Cocoa then think that I didn't add the
"buffersEmpty" observer when I clearly did?
The crash happens here, in the MagnatuneAppDelegate -stopStream
method:
- (void)stopStream
{
if (streamer)
{
[streamer removeObserver:self forKeyPath:@"buffersEmpty"];
[streamer stop];
}
}
With the code you've shown, it appears you'd crash exactly like that
if 'stopSteam' was called twice. If that's a possibility, you'd want
something like:
- (void)stopStream
{
if (streamer)
{
[streamer removeObserver:self forKeyPath:@"buffersEmpty"];
[streamer stop];
streamer = nil; // add appropriate memory management here, of course
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden