This code has been around far longer than I have but I'm trying to figure it out.
We have a Singleton object called CourseManager
. We also have an object called CourseSession
. The CourseManager singleton is the only one who creates and retains an instance of the CourseSession.
Now, in the CourseSessions, there is an NSMutableArray workingListStack
.
Some TableView is attempting to get the workingListStack like this...
self.navigationStack = [[[CourseManager sharedInstance] workingListStack] mutableCopy].
Now, CourseManager doesn't have workingListStack, CourseSession does. The way it achieves this is through a forwardInvocation function on CourseManager.
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
if ([self.session respondsToSelector:anInvocation.selector]) {
[anInvocation invokeWithTarget:self.session]; //this line
}
else {
[super forwardInvocation:anInvocation];
}
}
Seems like a weird way to go about things. If anyone knows why this may have been originally created like this, I'd love to hear it.
Anyway, back to the point. The 4th line in the snippet above calls this code on CourseSession...
1 - (NSMutableArray *)workingListStack
2 {
3 @synchronized(_workingListStack)
4 {
5 if (!_workingListStack || [_workingListStack count] == 0) {
6 _workingListStack = [NSMutableArray array];
7 [_workingListStack addObject:[self alphaAndOmegaRoot]];
8 }
9 else {
10 [_workingListStack replaceObjectAtIndex:0 withObject:[self alphaAndOmegaRoot]];
11 }
12 return _workingListStack;
13 }
14 }
From Crashlytics, I'm receiving the crash on line 13. (Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000d179bc17)
That seems like a weird line for the crash. Does this perhaps mean the _workingListStack that is being synchronized on line 3 is nil? Would you receive a crash when trying to synchronize on nil? What could cause this?
EDIT: Full Crashlytics Crash Log:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x246c06d8 objc_release + 7
1 T 0x186833 -[CourseSessionInternal workingListStack] (CourseSessionInternal.m:1003)
2 CoreFoundation 0x24edecc4 __invoking___ + 68
3 CoreFoundation 0x24e092ad -[NSInvocation invoke] + 292
4 CoreFoundation 0x24e0cd47 -[NSInvocation invokeWithTarget:] + 50
5 T 0x3ff103 -[CourseSessionManager forwardInvocation:] (CourseSessionManager.m:192)
6 CoreFoundation 0x24edd5b1 ___forwarding___ + 352
7 CoreFoundation 0x24e0cc88 _CF_forwarding_prep_0 + 24
8 T 0x2c6537 -[StudentModuleListTableView resetView] (StudentModuleListTableView.m:48)
9 T 0x2c7b4d __80-[StudentModuleListTableView observeValueForKeyPath:ofObject:change:context:]_block_invoke (StudentModuleListTableView.m:175)
10 libdispatch.dylib 0x24a77dd7 _dispatch_call_block_and_release + 10
11 libdispatch.dylib 0x24a77dc3 _dispatch_client_callout + 22
12 libdispatch.dylib 0x24a7c671 _dispatch_main_queue_callback_4CF + 1532
13 CoreFoundation 0x24e9cfc5 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
14 CoreFoundation 0x24e9b4bf __CFRunLoopRun + 1590
15 CoreFoundation 0x24dedbb9 CFRunLoopRunSpecific + 516
16 CoreFoundation 0x24ded9ad CFRunLoopRunInMode + 108
17 GraphicsServices 0x26067af9 GSEventRunModal + 160
18 UIKit 0x290d9fb5 UIApplicationMain + 144
19 T 0x120673 main (main.m:16)
20 libdispatch.dylib 0x24aa0873 (Missing)