IOS4.2应用程序退出EXC_BAD_ACCESS

时间:2010-12-08 08:44:09

标签: objective-c nsoperationqueue ios-4.2

在IOS3下运行良好的iPad应用程序在IOS4.2下运行失败它有一个从操作队列运行http会话的类,故障与此活动相关联。这是控制台输出:

Program received signal:  “EXC_BAD_ACCESS”.
[Switching to thread 11523]

启用运行NSZombies没有显示任何内容,所以我一直在代码中放置NSLog语句,发现当局部变量发生更改时发生崩溃。这是代码部分:

self.currentOperation = [[[DeduceAccessOperation alloc] init] autorelease];
[self.currentOperation addObserver:self forKeyPath:@"isFinished"
 options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
 context:NULL];
NSLog (@"Start observer added");    
[operationQueue addOperation:self.currentOperation];
NSLog (@"Start operation added");
NSLog(@"State is %d", self.status);
self.status = IEnablerServiceUpdating;
NSLog (@"State updated");

这是控制台日志输出:

2010-12-08 21:26:44.548 UCiEnabler[5180:307] Start observer added
2010-12-08 21:26:44.550 UCiEnabler[5180:307] Start operation added
2010-12-08 21:26:44.552 UCiEnabler[5180:307] State is 1
Program received signal:  “EXC_BAD_ACCESS”.
[Switching to thread 11523]

状态变为只读(它的属性被声明为原子和读写)。

另一个相关的信息是子视图刚刚被更改,它触发了上述例程的调用。它的代码是:

//Start the update      
UCiEnablerAppDelegate *controller = (UCiEnablerAppDelegate *)[[UIApplication sharedApplication] delegate];
[controller deduceIEnablerServiceAccess];
controller.serviceBusy = TRUE; //1.04

有没有人见过这样的东西?

有没有人想到下一步要去哪儿?

此致 罗宾

这是堆栈跟踪:

#0  0x34a80464 in objc_msgSend
#1  0x3119543e in NSKVOPendingNotificationCreate
#2  0x3119535a in NSKeyValuePushPendingNotificationPerThread
#3  0x3117009a in NSKeyValueWillChange
#4  0x311682c6 in -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:]
#5  0x311cc718 in _NSSetIntValueAndNotify
#6  0x000097ce in -[IEnablerService startDeducingAccessState] at IEnablerService.m:55
#7  0x00002bc0 in -[UCiEnablerAppDelegate deduceIEnablerServiceAccess] at UCiEnablerAppDelegate.m:100
#8  0x0000a33e in -[RootViewControlleriPad animationDidStop:finished:context:] at RootViewController-iPad.m:43
#9  0x341bb336 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]

1 个答案:

答案 0 :(得分:0)

iOS 4.2中的

NSOperationQueue现在在启动NSOperations时使用GrandCentralDispatch。 There's a Technical Q&A here

现在,无论NSOperation属性如何,队列现在都会在新线程中调用start子类的isConcurrent方法。根据我的经验,这意味着如果您在NSURLConnection方法中使用start,则代码将不再运行,因为正在运行的线程start没有NSRunLoop

Apple表示此更改不会破坏兼容性,因为您应该在start方法中生成新线程。

为了向后兼容,您应该将子类从使用start更改为使用run