Crash on NSKVOPendingNotificationRelease (KVO, bindings issue?)
Crash on NSKVOPendingNotificationRelease (KVO, bindings issue?)
- Subject: Crash on NSKVOPendingNotificationRelease (KVO, bindings issue?)
- From: Glen Low <email@hidden>
- Date: Thu, 22 Apr 2010 08:47:27 +0800
I'm using KVO as a generalized recalculation engine, somewhat akin to how a spreadsheet recalcuates values based on what's changed. It's mostly successful once you eliminate cycles, but there is a persistent problem.
On each relevant object, I have a observeValueForKeyPath:ofObject:change:context: method which then triggers willChangeValueForKey: / didChangeValueForKey: for dependent properties. I've noticed that when observeValueForKeyPath:ofObject:change:context gets called more than once in a row for an object, one of the other observed objects dies in didChangeValueForKey: -- here's the stack trace
Program received signal: “EXC_BAD_ACCESS”.
#0 0x7fff84d31ae1 in NSKVOPendingNotificationRelease
#1 0x7fff88aa0bd3 in __CFArrayReleaseValues
#2 0x7fff88a815f8 in _CFArrayReplaceValues
#3 0x7fff84d31e35 in NSKeyValuePopPendingNotificationPerThread
#4 0x7fff84d31dca in NSKeyValueDidChange
#5 0x7fff84d1574f in -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:]
#6 0x1000181c8 in -[CMEdge didChangeValueOnceForKey:] at CMEdge.m:133
#7 0x100019f51 in -[CMNode observeValueForKeyPath:ofObject:change:context:] at CMNode.m:222
The only workaround is to perform the didChangeValueForKey: in the next event cycle i.e. by using performSelectorOnMainThread:withObject:waitUntilDone:
Not really ideal especially since I'm worried I'm just covering up the root of the problem, whatever it is.
Any ideas on the cause?
Side question: I can of course use keyPathsForValuesAffectingValueForKey: and friends to declare the dependencies instead of using a procedure to react to them, but I need to execute code as well e.g. update the observed value. For example, say A = B/C. When either B or C changes, you want A to change too. I can use keyPathsForValuesAffectingA to declare it depends on B or C, but I need to update the cached A value whenever B or C changes -- how would I do that without using observeValueForKeyPath:ofObject:change:context:?
Cheers
Glen Low
Pixelglow Software_______________________________________________
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