I am debugging very old code that is still being used in our app due to a crash that it's causing in our app. The error is Objective-C related:
The crash:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TrackService exit]: unrecognized selector sent to instance 0x281cb4380'
The code where it crashes:
@implementation TrackService
+ (TrackService *)sharedService
{
DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
return [[self alloc] init];
});
}
/*
GCD Singleton
*/
#define DEFINE_SHARED_INSTANCE_USING_BLOCK(block) \
static dispatch_once_t pred = 0; \
__strong static id _sharedObject = nil; \
dispatch_once(&pred, ^{ \
_sharedObject = block(); \
}); \
\
return _sharedObject;
#endif
Stack Trace:
2020-02-11 09:49:35.737492+0200 TestApp[79860:6925721] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TrackService exit]: unrecognized selector sent to instance 0x600001dc6380'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ee3b1bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010e3d9735 objc_exception_throw + 48
2 CoreFoundation 0x000000010ee59f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010ee3fed6 ___forwarding___ + 1446
4 CoreFoundation 0x000000010ee41da8 _CF_forwarding_prep_0 + 120
5 TestApp 0x00000001029b6575 $s2017fromNavControllerSbSS_SDySSypGSgSo012UINavigationK0CSgtFySSSgcfU13_ + 165
6 TestApp 0x00000001029b663f $sSSSgIegg_So8NSStringCSgIeyBy_TR + 175
7 TestApp 0x000000010249decf -[TrackViewController exit:] + 1551
8 TestApp 0x000000010249e275 __36-[TrackViewController exit:]_block_invoke + 757
9 TestApp 0x000000010246834c -[TrackViewController pickAction:] + 220
10 UIKitCore 0x0000000115a2cecb -[UIApplication sendAction:to:from:forEvent:] + 83
11 UIKitCore 0x000000011516d95b __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 154
12 UIKitCore 0x000000011516d894 -[_UIButtonBarTargetAction _invoke:forEvent:] + 152
13 UIKitCore 0x0000000115a2cecb -[UIApplication sendAction:to:from:forEvent:] + 83
14 UIKitCore 0x00000001154680bd -[UIControl sendAction:to:forEvent:] + 67
15 UIKitCore 0x00000001154683da -[UIControl _sendActionsForEvents:withEvent:] + 450
16 UIKitCore 0x000000011546731e -[UIControl touchesEnded:withEvent:] + 583
17 UIKitCore 0x0000000115a680a4 -[UIWindow _sendTouchesForEvent:] + 2729
18 UIKitCore 0x0000000115a697a0 -[UIWindow sendEvent:] + 4080
19 UIKitCore 0x0000000115a47394 -[UIApplication sendEvent:] + 352
20 UIKitCore 0x0000000115b1c5a9 __dispatchPreprocessedEventFromEventQueue + 3054
21 UIKitCore 0x0000000115b1f1cb __handleEventQueueInternal + 5948
22 CoreFoundation 0x000000010eda0721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
23 CoreFoundation 0x000000010ed9ff93 __CFRunLoopDoSources0 + 243
24 CoreFoundation 0x000000010ed9a63f __CFRunLoopRun + 1263
25 CoreFoundation 0x000000010ed99e11 CFRunLoopRunSpecific + 625
26 GraphicsServices 0x00000001141fc1dd GSEventRunModal + 62
27 UIKitCore 0x0000000115a2b81d UIApplicationMain + 140
28 TestApp 0x000000010262672b main + 75
29 libdyld.dylib 0x0000000110ab5575 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The code crashes on this line TrackService.shared().exit()