my app is crashed when the user tapped on a marker (GMSMapVIew: didTapMarker) and myApp works good in 99% of the time, But sometimes it shows a crash on crashlytics. And it's so random occurred.
The crash report shows the following.
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000002f6ce97f4
-[BadgerMapView mapView:didTapMarker:]
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1f025653c objc_msgSend + 28
1 Badger 0x104d3af84 -[BadgerMapView mapView:didTapMarker:] + 1784 (BadgerMapView.m:1784)
2 CoreFoundation 0x1f106b900 __invoking___ + 144
3 CoreFoundation 0x1f0f4d4d0 -[NSInvocation invoke] + 292
4 CoreFoundation 0x1f0f4e104 -[NSInvocation invokeWithTarget:] + 60
5 Badger 0x104e940e0 -[GMSDelegateForward forwardInvocation:] + 4339744992
6 CoreFoundation 0x1f10697c0 ___forwarding___ + 636
7 CoreFoundation 0x1f106b75c _CF_forwarding_prep_0 + 92
8 Badger 0x104ea01fc -[GMSMapView didTapMarker:] + 20436
9 Badger 0x104eb8a88 -[GMSMarker wasTapped] + 120928
10 UIKitCore 0x21d1c3868 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64
11 UIKitCore 0x21d1cba70 _UIGestureRecognizerSendTargetActions + 124
12 UIKitCore 0x21d1c9414 _UIGestureRecognizerSendActions + 316
13 UIKitCore 0x21d1c8940 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 760
14 UIKitCore 0x21d1bca1c _UIGestureEnvironmentUpdate + 2180
15 CoreFoundation 0x1f0ff55f8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
16 CoreFoundation 0x1f0ff0320 __CFRunLoopDoObservers + 412
17 CoreFoundation 0x1f0ff089c __CFRunLoopRun + 1228
18 CoreFoundation 0x1f0ff00b0 CFRunLoopRunSpecific + 436
19 GraphicsServices 0x1f31f079c GSEventRunModal + 104
20 UIKitCore 0x21d59a978 UIApplicationMain + 212
21 Badger 0x104cb863c main + 17 (main.m:17)
22 libdyld.dylib 0x1f0ab58e0 start + 4
Below is my code where the app is crash.
BadgerMapView.m:1784
if (![waypt isKindOfClass:[NSNull class]]) This is the line where i got crash
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
CLLocationCoordinate2D markerLocation = marker.position;
double tappedMarkerLattitude = markerLocation.latitude;
double tappedMarkerLongitude = markerLocation.longitude;
NSArray *waypoints =[MapViewController sharedInstance].wayPointsToShowOnRouteMode;
for (PlannerWaypoint *waypt in waypoints)
{
#try {
if (![waypt isKindOfClass:[NSNull class]]) {
if (![waypt isEqual:nil]) {
[MapViewController sharedInstance].currentWaypoint = waypt;
NSNumber *nextWayPointIndex = [MapViewController sharedInstance].currentWaypoint.modPosition;
NSNumber *prevWayPointIndex = [MapViewController sharedInstance].currentWaypoint.modPosition;
int value = [nextWayPointIndex intValue];
nextWayPointIndex = [NSNumber numberWithInt:value + 1];
NSUInteger nextWayPointIndexInt = [nextWayPointIndex integerValue];
prevWayPointIndex = [NSNumber numberWithInt:value - 1];
NSUInteger prevWayPointIndexInt = [prevWayPointIndex integerValue];
int waypointCount = (int)[waypoints count];
if (nextWayPointIndexInt > (waypointCount-1)) {
[MapViewController sharedInstance].nextWaypoint = [waypoints objectAtIndex:0];
}
else {
[MapViewController sharedInstance].nextWaypoint = [waypoints objectAtIndex:nextWayPointIndexInt];
}
if (prevWayPointIndexInt > (waypointCount-1)) {
[MapViewController sharedInstance].previousWaypoint = [waypoints objectAtIndex:(waypointCount-1)];
}
else {
[MapViewController sharedInstance].previousWaypoint = [waypoints objectAtIndex:prevWayPointIndexInt];
}
if([Utility isIphone] == NO) {
[[MapViewController sharedInstance] showMarkerSelectedAtMiddle:[MapViewController sharedInstance].currentWaypoint];
UIViewController *viewcontroller = [MenuViewController sharedInstance].presentedViewController;
if([viewcontroller.childViewControllers objectAtIndex:0]!=nil) {
RouteModeViewController *routeModeView = [viewcontroller.childViewControllers objectAtIndex:0];
[routeModeView.customerCardNameLabel setText:[MapViewController sharedInstance].waypointLabel];
}
} else {
UINavigationController *UINavController = (UINavigationController *)self.window.rootViewController.presentedViewController;
UIViewController *UIViewCon = [[UINavController viewControllers] lastObject];
if ([UIViewCon isKindOfClass:[MapViewController class]]) {
MapViewController *mapViewController = (MapViewController *)UIViewCon;
[mapViewController showMarkerSelectedAtMiddle:waypt];
}
}
[waypt release];
waypt = nil;
break;
}
}
} #catch (NSException *exception) {
NSLog(#"Exception in ProcessdidTapMarker: %#",exception);
[DeviceLoger log:[NSString stringWithFormat:#"Exception in ProcessdidTapMarker: %#",exception]];
}
}
return YES;
}
Does anybody have an idea?
Please help me, Because I'm facing this issue form a very long time
Thanks!
Related
I'm developing an app with Unity that uses Digital Ink Recognition of ML Kit to recognize handwriting.
To fetch ios plugin via unity, I use this script:
public static void Initialize(string languageTag = "en-US")
{
if (_instance != null)
{
return;
}
Debug.Log("Initializing...");
GameObject owner = new GameObject("HandwriteRecognitionIOSPluguin");
_instance = owner.AddComponent<HandwriteRecognitionIOSPluguin>();
_InitializeNew(languageTag);
}
from the above function will be directed to the objective-c script with the following script:
static DigitalInkRecognition* recognition = nil;
extern "C" void _InitializeNew(const char* languageTag)
{
if (recognition == nil)
recognition = [[DigitalInkRecognition alloc] init];
[recognition downloadModel];
}
the following is the script in the objective-c file
#import <GoogleMLKit/MLKit.h>
#interface DigitalInkRecognition : NSObject
#property(nonatomic) MLKDigitalInkRecognitionModel *model;
#property(nonatomic) MLKModelManager *modelManager;
#property(nonatomic) MLKDigitalInkRecognitionModelIdentifier *identifier;
#property(weak, nullable, nonatomic) id delegate;
#end
#implementation DigitalInkRecognition : NSObject
- (id)init
{
self = [super init];
_modelManager = [MLKModelManager modelManager];
_delegate = self;
__weak __typeof(self) weakSelf = self;
[NSNotificationCenter.defaultCenter
addObserverForName:MLKModelDownloadDidSucceedNotification
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *notification) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf == nil) {
NSLog(#"self == nil handling download success notification");
return;
}
if ([notification.userInfo[MLKModelDownloadUserInfoKeyRemoteModel]
isEqual:strongSelf.model]) {
[strongSelf.delegate displayMessage:#"Model download succeeded"];
}
}];
[NSNotificationCenter.defaultCenter
addObserverForName:MLKModelDownloadDidFailNotification
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *notification) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf == nil) {
NSLog(#"self == nil handling download fail notification");
return;
}
if ([notification.userInfo[MLKModelDownloadUserInfoKeyRemoteModel]
isEqual:strongSelf.model]) {
[strongSelf.delegate displayMessage:#"Model download failed"];
}
}];
NSString *language = [[NSLocale preferredLanguages] firstObject];
self.identifier =
[MLKDigitalInkRecognitionModelIdentifier modelIdentifierFromLanguageTag:language error:nil];
[self displayMessage:language];
if (self.identifier == nil) {
self.identifier = [MLKDigitalInkRecognitionModelIdentifier modelIdentifierFromLanguageTag:#"en" error:nil];
}
return self;
}
- (IBAction)downloadModel {
if ([self.modelManager isModelDownloaded:self.model]) {
[self.delegate displayMessage:#"Model is already downloaded"];
return;
}
[self.delegate displayMessage:#"Starting download"];
self.model = [[MLKDigitalInkRecognitionModel alloc] initWithModelIdentifier:self.identifier];
self.modelManager = [MLKModelManager modelManager];
//ERROR HERE
[self.modelManager downloadModel:self.model
conditions:[[MLKModelDownloadConditions alloc]
initWithAllowsCellularAccess:YES
allowsBackgroundDownloading:YES]];
}
- (void)displayMessage:(NSString *)message {
NSLog(#"LOG MESSAGE :: %#", message);
}
#end
When entering the 'downloadModel' function, the script will error with the following message:
2022-01-24 13:11:33.828766+0700 appdev[734:210369] +[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10
2022-01-24 13:11:33.868910+0700 appdev[734:210369] Uncaught exception: NSInvalidArgumentException: +[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10
(
0 CoreFoundation 0x00000001804c6d50 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 597328
1 libobjc.A.dylib 0x000000019782b6a8 objc_exception_throw + 56
2 CoreFoundation 0x00000001805966b0 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 1447600
3 CoreFoundation 0x0000000180460f6c 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 180076
4 CoreFoundation 0x00000001804601dc _CF_forwarding_prep_0 + 92
5 UnityFramework 0x00000001081933ac -[MLKDigitalInkRecognitionLogger logEvent:withName:] + 92
6 UnityFramework 0x00000001081949bc -[MLKDigitalInkLogEvent log] + 424
7 UnityFramework 0x000000010819752c -[MLKDigitalInkRecognitionModelManager downloadModel:conditions:] + 328
8 UnityFramework 0x0000000108132e28 -[MLKModelManager downloadModel:conditions:] + 224
9 UnityFramework 0x0000000108124964 -[DigitalInkRecognition downloadModel] + 588
10 UnityFramework 0x000000010945a8a4 HandwriteRecognitionIOSPluguin_Initialize_mC4FA5B192BDF0E20E606D3DC32DFB3A71C363767 + 288
11 UnityFramework 0x000000010945b7cc IOSHandwritingManager_U3CStartU3Eb__17_0_m0444198A2E9188E1DC9F9A84E34AC1E1C22A03C5 + 180
12 UnityFramework 0x0000000109556bc4 UnityAction_Invoke_mC9FF5AA1F82FDE635B3B6644CE71C94C31C3E71A + 276
13 UnityFramework 0x000000010955d9cc UnityEvent_Invoke_mB2FA1C76256FE34D5E7F84ABE528AC61CE8A0325 + 348
14 UnityFramework 0x000000010952b6d8 EventFunction_1_Invoke_m7899B7663B08CD474B8FADD9D85FF446CD839FE6_gshared + 504
15 UnityFramework 0x00000001094661f0 ExecuteEvents_Execute_TisRuntimeObject_mDA4CD02F963B6939F8D079993DC2DCD75AB524DD_gshared + 308
16 UnityFramework 0x0000000109595a7c StandaloneInputModule_ProcessTouchPress_m74A52DA64B9C5EB8B5A38889F25BFEAFC284FB51 + 1216
17 UnityFramework 0x0000000109595060 StandaloneInputModule_ProcessTouchEvents_mFEED66642E804A218DD34A9C5F0F8EAA5CA3B019 + 248
18 UnityFramework 0x0000000109594d9c StandaloneInputModule_Process_mBF40EA3762B85C417E6F88D531174D05A7FFCE75 + 72
19 UnityFramework 0x00000001080f50ac _Z65RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017PFvvEPK10MethodInfoPvPS4_ + 20
20 UnityFramework 0x0000000109440e5c _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 116
21 UnityFramework 0x00000001090fa620 _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 116
22 UnityFramework 0x0000000109105268 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 116
23 UnityFramework 0x0000000109110954 _ZN13MonoBehaviour16CallUpdateMethodEi + 300
24 UnityFramework 0x0000000108f96668 _ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv + 224
25 UnityFramework 0x000000010905e588 _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 88
26 UnityFramework 0x000000010905e5bc _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 140
27 UnityFramework 0x000000010905e824 _Z10PlayerLoopv + 356
28 UnityFramework 0x0000000109255784 _ZL19UnityPlayerLoopImplb + 224
29 UnityFramework 0x00000001080be714 UnityRepaint + 140
30 UnityFramework 0x00000001080be5f0 -[UnityAppController(Rendering) repaintDisplayLink] + 88
31 QuartzCore 0x0000000183f5cd1c 36E47EF8-38B9-36C6-95B4-7AF8527D7E9D + 64796
32 QuartzCore 0x0000000183f634e8 36E47EF8-38B9-36C6-95B4-7AF8527D7E9D + 91368
33 CoreFoundation 0x000000018043f69c 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 42652
34 CoreFoundation 0x000000018047f4ec 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 304364
35 CoreFoundation 0x0000000180482adc 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 318172
36 CoreFoundation 0x00000001804400f0 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 45296
37 CoreFoundation 0x0000000180452e1c CFRunLoopRunSpecific + 572
38 GraphicsServices 0x00000001a07e19a0 GSEventRunModal + 160
39 UIKitCore 0x0000000182c86600 D8869DEE-E238-3284-8C9A-623313659320 + 5162496
40 UIKitCore 0x0000000182a1bb08 UIApplicationMain + 2028
41 UnityFramework 0x00000001080bd0f0 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 108
42 appdev 0x00000001001e7e84 main + 68
43 dyld 0x0000000101e34250 start + 444
)
2022-01-24 13:11:33.870345+0700 appdev[734:210369] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10'
*** First throw call stack:
(0x1804c6d3c 0x19782b6a8 0x1805966b0 0x180460f6c 0x1804601dc 0x1081933ac 0x1081949bc 0x10819752c 0x108132e28 0x108124964 0x10945a8a4 0x10945b7cc 0x109556bc4 0x10955d9cc 0x10952b6d8 0x1094661f0 0x109595a7c 0x109595060 0x109594d9c 0x1080f50ac 0x109440e5c 0x1090fa620 0x109105268 0x109110954 0x108f96668 0x10905e588 0x10905e5bc 0x10905e824 0x109255784 0x1080be714 0x1080be5f0 0x183f5cd1c 0x183f634e8 0x18043f69c 0x18047f4ec 0x180482adc 0x1804400f0 0x180452e1c 0x1a07e19a0 0x182c86600 0x182a1bb08 0x1080bd0f0 0x1001e7e84 0x101e34250)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10'
(lldb)
on error, script goes to file 'main.mm' line 26 ([ufw runUIApplicationMainWithArgc: argc argv: argv];). The following is the contents of the 'main.mm' file:
#include <UnityFramework/UnityFramework.h>
UnityFramework* UnityFrameworkLoad()
{
NSString* bundlePath = nil;
bundlePath = [[NSBundle mainBundle] bundlePath];
bundlePath = [bundlePath stringByAppendingString: #"/Frameworks/UnityFramework.framework"];
NSBundle* bundle = [NSBundle bundleWithPath: bundlePath];
if ([bundle isLoaded] == false) [bundle load];
UnityFramework* ufw = [bundle.principalClass getInstance];
if (![ufw appController])
{
// unity is not initialized
[ufw setExecuteHeader: &_mh_execute_header];
}
return ufw;
}
int main(int argc, char* argv[])
{
#autoreleasepool
{
id ufw = UnityFrameworkLoad();
[ufw runUIApplicationMainWithArgc: argc argv: argv];
return 0;
}
}
What can I do to solve the problem I'm having?
Thanks in advance for any idea.
I have a viewController that manages a UICollectionView. I have a helper method that is called from cellForItemAtIndexPath that provides an NSAttributedString for a label in the cell. The helper method formats an NSAttributedString from an html string. The app will crash when moving to the background, but only if the indexPath.item is greater than 1. In other words, I can exit the app without crashing from the first or second cell, but crash consistently on the third, forth, ... cell.
Here are my helper method and stack trace. Any idea why I am crashing on exiting the app?
#pragma mark - === Utility Methods === -
- (NSAttributedString *)stepDescriptionStringForIndexPath:(NSIndexPath *)indexPath {
NSString *headerString;
NSString *htmlString;
NSString *categoryString = [NSString stringWithFormat:#"Category: %#", self.knot.category.categoryName];
NSString *abokString = [NSString stringWithFormat:#"ABOK #: %#", self.knot.abokNumber];
NSMutableString *activitiesString = [NSMutableString stringWithCapacity:10];
[activitiesString appendString:#"Activities: "];
// build a string of activities to append to the description html
NSArray *activities = [self.knot.activities allObjects];
if ([activities count] > 0) {
int counter = 1;
for (Activity *activity in activities) {
[activitiesString appendString:activity.activityName];
if (counter < [activities count]) {
[activitiesString appendString:#", "];
}
counter ++;
}
}
// build an HTML string by concatinating the activities to the step description
// and add the header string
if(indexPath.item > 0){
Step *step = (Step *)self.steps[indexPath.item - 1];
headerString = [NSString stringWithFormat:#"Step %ld of %lu", (long)indexPath.item, (unsigned long)[self.steps count]];
htmlString =[NSString stringWithFormat:#"<p>%#</p>%#", headerString, step.stepDescription];
} else {
headerString = #"Overview";
htmlString = [NSString stringWithFormat:#"<p>%#</p>%#<p>%#</br>%#</br>%#</p>", headerString, self.knot.knotDescription, categoryString, abokString, activitiesString];
}
// convert the html string to an attributed string
NSMutableAttributedString *attrStringFromHTML = [[NSMutableAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding]
options:#{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:nil
error:nil];
// set the font for the body
NSRange totalRange;
totalRange.location = 0;
totalRange.length = attrStringFromHTML.length;
[attrStringFromHTML addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:totalRange];
// set the font for the header
NSString *temp = [attrStringFromHTML string];
NSRange headerRange = [temp rangeOfString:headerString];
NSRange categoryRange = [temp rangeOfString:categoryString];
NSRange abokRange = [temp rangeOfString:abokString];
NSRange activitiesRange = [temp rangeOfString:activitiesString];
[attrStringFromHTML addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:18] range:headerRange];
//set the font for the activities paragraph
if(indexPath.item == 1){
[attrStringFromHTML addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:categoryRange];
[attrStringFromHTML addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:abokRange];
[attrStringFromHTML addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:activitiesRange];
}
return attrStringFromHTML;
}
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unexpected start state'
*** First throw call stack:
(
0 CoreFoundation 0x00000001131aad85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000112c1edeb objc_exception_throw + 48
2 CoreFoundation 0x00000001131aabea +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000110b96e1e -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 169
4 UIKit 0x00000001113a7d4e _prepareForCAFlush + 256
5 UIKit 0x00000001113b40b4 _beforeCACommitHandler + 12
6 CoreFoundation 0x00000001130cfc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
7 CoreFoundation 0x00000001130cfba7 __CFRunLoopDoObservers + 391
8 CoreFoundation 0x00000001130c511c CFRunLoopRunSpecific + 524
9 UIFoundation 0x000000011a697a7a -[NSHTMLReader _loadUsingWebKit] + 2093
10 UIFoundation 0x000000011a698e74 -[NSHTMLReader attributedString] + 22
11 UIFoundation 0x000000011a6323c0 _NSReadAttributedStringFromURLOrData + 5623
12 UIFoundation 0x000000011a630d34 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 115
13 WhatKnotToDo 0x000000010e84d3ac -[CSC_iPad_KnotDetailViewController stepDescriptionStringForIndexPath:] + 2476
14 WhatKnotToDo 0x000000010e84c31d -[CSC_iPad_KnotDetailViewController collectionView:cellForItemAtIndexPath:] + 477
15 UIKit 0x0000000111bff08f -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] + 483
16 UIKit 0x0000000111c02d96 -[UICollectionView _updateVisibleCellsNow:] + 4988
17 UIKit 0x0000000111c07575 -[UICollectionView layoutSubviews] + 258
18 UIKit 0x0000000111442980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
19 QuartzCore 0x0000000112af6c00 -[CALayer layoutSublayers] + 146
20 QuartzCore 0x0000000112aeb08e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
21 QuartzCore 0x0000000112aeaf0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
22 QuartzCore 0x0000000112adf3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
23 QuartzCore 0x0000000112b0d086 _ZN2CA11Transaction6commitEv + 486
24 UIKit 0x0000000111394a0b __65-[UIApplication _beginSnapshotSessionForScene:withSnapshotBlock:]_block_invoke2222 + 601
25 UIKit 0x0000000111395201 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke2243 + 131
26 FrontBoardServices 0x00000001153e3039 -[FBSSceneSnapshotAction _finishAllRequests] + 65
27 FrontBoardServices 0x00000001153e2de3 -[FBSSceneSnapshotAction executeRequestsWithHandler:completionHandler:expirationHandler:] + 218
28 UIKit 0x0000000111395024 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke + 305
29 UIKit 0x0000000111394592 -[UIApplication _beginSnapshotSessionForScene:withSnapshotBlock:] + 1138
30 UIKit 0x0000000111394eb2 -[UIApplication _performSnapshotsWithAction:forScene:completion:] + 629
31 UIKit 0x0000000111394bbc -[UIApplication _handleSnapshotAction:forScene:completion:] + 153
32 UIKit 0x0000000111390a8f __102-[UIApplication _handleApplicationDeactivationWithScene:shouldForceExit:transitionContext:completion:]_block_invoke1993 + 290
33 UIKit 0x0000000111390657 __102-[UIApplication _handleApplicationDeactivationWithScene:shouldForceExit:transitionContext:completion:]_block_invoke1979 + 1258
34 UIKit 0x0000000111393f62 _runAfterCACommitDeferredBlocks + 317
35 UIKit 0x00000001113a7e4c _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
36 UIKit 0x00000001113b4147 _afterCACommitHandler + 90
37 CoreFoundation 0x00000001130cfc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
38 CoreFoundation 0x00000001130cfba7 __CFRunLoopDoObservers + 391
39 CoreFoundation 0x00000001130c57fb __CFRunLoopRun + 1147
40 CoreFoundation 0x00000001130c50f8 CFRunLoopRunSpecific + 488
41 GraphicsServices 0x0000000115203ad2 GSEventRunModal + 161
42 UIKit 0x0000000111387f09 UIApplicationMain + 171
43 WhatKnotToDo 0x000000010e820b7f main + 111
44 libdyld.dylib 0x000000011396592d start + 1
45 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've come across this issue too, after a few hours, i've found a solution for this one.
You'll just need to wrap the code for converting the NSAttributedString into dispatch_async.
For example:
DispatchQueue.MainQueue.DispatchAsync(() =>
{
var encodingData = ((NSString)html).Encode(NSStringEncoding.Unicode, true);
NSAttributedString data = new NSAttributedString(
encodingData,
new NSAttributedStringDocumentAttributes()
{
DocumentType = NSDocumentType.HTML,
}, ref error);
});
I'm using Xamarin, so these are C# code, but i believe they're similar in Swift and Obj C.
Look like when the system is making transition between pages (view controller), it will try to prevent any heavy task running on UI Thread. Which cause this issue.
I'm checking self.next_id is not null why would this line crash? I can't reproduce the issue on my test devices. I only get crash reports from Crashlytics at this line.
-(Second*)getNextSecond:(BOOL)returnSelf{
Second* retValue = nil;
if(self.next_id){
//this line !!!!
retValue = [[SecondDatabase sharedManager] getSecond:[self.next_id stringValue]];
}
if (retValue == nil && returnSelf) {
return self;
}else{
return retValue;
}
}
This is my SecondDatabase sharedManager function:
#property NSMutableDictionary* dictionary;
- (id)init {
if (self = [super init]) {
_dictionary = [#{} mutableCopy];
}
return self;
}
+ (id)sharedManager {
static SecondDatabase *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
This is my getSecond function:
-(Second*)getSecond:(NSString*)idString{
return [_dictionary objectForKey:idString];
}
Where should I be investigating? Would this crash if dictionary didn't have object for key so that it returns NULL?
My crash report:
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x000007d8
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x3acd164c realizeClass(objc_class*) + 19
1 libobjc.A.dylib 0x3acd1715 realizeClass(objc_class*) + 220
2 libobjc.A.dylib 0x3acd1715 realizeClass(objc_class*) + 220
3 libobjc.A.dylib 0x3acd39ab lookUpImpOrForward + 74
4 libobjc.A.dylib 0x3acd3957 _class_lookupMethodAndLoadCache3 + 34
5 libobjc.A.dylib 0x3acd88b9 _objc_msgSend_uncached + 24
6 itsmysecond-ios 0x001287c7 -[Second getNextSecond:] (Second.m:93)
7 itsmysecond-ios 0x000fd5ff -[EBParallaxViewController adjustViewsToSeconds] (EBParallaxViewController.m:181)
8 itsmysecond-ios 0x000fd21d -[EBParallaxViewController scrollViewDidEndDecelerating:] (EBParallaxViewController.m:154)
9 UIKit 0x32ed6957 -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 806
10 UIKit 0x32e0cd47 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 466
11 UIKit 0x32e0cb6b -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
12 UIKit 0x32ed621b -[UIScrollView _smoothScrollWithUpdateTime:] + 3322
13 QuartzCore 0x32a06df3 CA::Display::DisplayLinkItem::dispatch() + 98
14 QuartzCore 0x32a06b9d CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 344
15 IOMobileFramebuffer 0x3577f75d IOMobileFramebufferVsyncNotifyFunc + 104
16 IOKit 0x31209451 IODispatchCalloutFromCFMessage + 248
17 CoreFoundation 0x304ddea9 __CFMachPortPerform + 136
18 CoreFoundation 0x304e8a67 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
19 CoreFoundation 0x304e8a03 __CFRunLoopDoSource1 + 346
20 CoreFoundation 0x304e71d7 __CFRunLoopRun + 1398
21 CoreFoundation 0x30451ebf CFRunLoopRunSpecific + 522
22 CoreFoundation 0x30451ca3 CFRunLoopRunInMode + 106
23 GraphicsServices 0x35357663 GSEventRunModal + 138
24 UIKit 0x32d9e14d UIApplicationMain + 1136
25 itsmysecond-ios 0x00109707 main (main.m:14)
26 libdyld.dylib 0x3b1dbab7 start + 2
I have two modes - Mode 1 and Mode 2 which can be switched by a central button. Switch between modes allows user to see two different types of clustered annotations.
I can switch from Mode 1 to Mode 2 easily, but when I switch back to Mode 1 I'm getting this nasty error
-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fb1308cca50
I'm opening my code and in the TBClusteredAnnotations.m (script I'm using for clusterization). I have the following snippet of code relating to componentsSeparatedByString:
TBQuadTreeNodeData TBDataFromLine(NSString *line)
{
NSString *separator=#">>>>>>>>";
NSArray *components = [line componentsSeparatedByString: separator];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
TBUserInfo* userInfo = malloc(sizeof(TBUserInfo));
NSString *userName = [components[2] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
userInfo->userId = malloc(sizeof(char) * userName.length + 1);
strncpy(userInfo->userId, [userName UTF8String], userName.length + 1);
NSString *userId = [components [3] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
userInfo->userImage = malloc(sizeof(char) * userId.length + 1);
strncpy(userInfo->userImage, [userId UTF8String], userId.length + 1);
return TBQuadTreeNodeDataMake(latitude, longitude, userInfo);
}
but I'm loading my annotations with the following code in the MainViewController:
-(void)annotationsmode1:(NSMutableArray*)marr
{
if(marr.count>0)
{
NSMutableArray *newMarr1=[NSMutableArray new];
NSString *separatestuff=#">>>>>>>>";
for(NSMutableDictionary *dic in marr)
{
NSString *newStr=[NSString stringWithFormat:#"%#%#",[dic[#"latitude"] isEqualToString:#""]?#" ":dic[#"latitude"],separatestuff];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"longitude"] isEqualToString:#""]?#" ":dic[#"longitude"],separatestuff];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"id"] isEqualToString:#""]?#" ":dic[#"id"],separatestuff];
newStr=[NSString stringWithFormat:#"%#%#",newStr,[dic[#"image"] isEqualToString:#""]?#" ":dic[#"image"]];
[newMarr1 addObject:newStr];
}
//NSLog(#"NEW Array: %#",newMarr);
[self.coordinateQuadTree buildTree:newMarr1];
}
}
-(void)annotationsmode2:(NSMutableArray*)marr
{
if(marr.count>0)
{
NSMutableArray *newMarr=[NSMutableArray new];
NSString *separatestuff2=#">>>>>>>>";
for(NSMutableDictionary *dic in marr)
{
NSString *newStr=[NSString stringWithFormat:#"%#%#",[dic[#"lat"] isEqualToString:#""]?#" ":dic[#"lat"],separatestuff2];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"lang"] isEqualToString:#""]?#" ":dic[#"lang"],separatestuff2];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"id"] isEqualToString:#""]?#" ":dic[#"id"],separatestuff2];
newStr=[NSString stringWithFormat:#"%#%#",newStr,[dic[#"image"] isEqualToString:#""]?#" ":dic[#"image"]];
[newMarr addObject:newStr];
}
//NSLog(#"NEW Array: %#",newMarr);
[self.coordinateQuadTree buildTree:newMarr];
}
}
UPDATE: This is the block of code where the TBDataFromLine is used
- (void)buildTree:(NSMutableArray *)lines
{
#autoreleasepool {
NSInteger count = lines.count - 1;
TBQuadTreeNodeData *dataArray = malloc(sizeof(TBQuadTreeNodeData) * count);
for (NSInteger i = 0; i < count; i++) {
dataArray[i] = TBDataFromLine(lines[i]);
}
//TBBoundingBox world = TBBoundingBoxMake(19, -166, 72, -53);
TBBoundingBox world = TBBoundingBoxMake(0,0,100,100);
_root = TBQuadTreeBuildWithData(dataArray, count, world, 4);
}
}
I've been working on this issue for hours now and still have no clue.
UPDATE: Here is the debugger's log I'm getting
2015-06-20 19:40:23.759 MapProject[13426:395344] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fdf93775680'
*** First throw call stack:
(
0 CoreFoundation 0x0000000112699c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001121c3bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001126a10ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001125f713c ___forwarding___ + 988
4 CoreFoundation 0x00000001125f6cd8 _CF_forwarding_prep_0 + 120
5 MapProject 0x000000010f469ac4 TBDataFromLine + 84
6 MapProject 0x000000010f46a36f -[TBCoordinateQuadTree buildTree:] + 191
7 MapProject 0x000000010f3d2503 -[MMViewController findSpot:] + 771
8 UIKit 0x0000000110a52da2 -[UIApplication sendAction:to:from:forEvent:] + 75
9 UIKit 0x0000000110b6454a -[UIControl _sendActionsForEvents:withEvent:] + 467
10 UIKit 0x0000000110b63919 -[UIControl touchesEnded:withEvent:] + 522
11 UIKit 0x0000000110a9f998 -[UIWindow _sendTouchesForEvent:] + 735
12 UIKit 0x0000000110aa02c2 -[UIWindow sendEvent:] + 682
13 UIKit 0x0000000110a66581 -[UIApplication sendEvent:] + 246
14 UIKit 0x0000000110a73d1c _UIApplicationHandleEventFromQueueEvent + 18265
15 UIKit 0x0000000110a4e5dc _UIApplicationHandleEventQueue + 2066
16 CoreFoundation 0x00000001125cd431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x00000001125c32fd __CFRunLoopDoSources0 + 269
18 CoreFoundation 0x00000001125c2934 __CFRunLoopRun + 868
19 CoreFoundation 0x00000001125c2366 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x000000011444da3e GSEventRunModal + 161
21 UIKit 0x0000000110a51900 UIApplicationMain + 1282
22 MapProject 0x000000010f474c2f main + 111
23 libdyld.dy
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Add an Exception break point and it will take to exactly to that line where that crash is happening. Also check 'line' cause it is changed to dictionary but you code expect it
to be a string
There is no [] operator on NSArray or NSMutableArray.
You need this:
for (NSInteger i = 0; i < count; i++) {
dataArray[i] = TBDataFromLine([lines objectAtIndex:i]);
}
Using [] on NSArray* effectively acted like "lines" was really a pointer to an array of NSMutableArray instances, whereas you wanted to get one of the items out of the array to which it pointed.
[self.kvoController observe:user keyPath: #"fullName" options:NSKeyValueObservingOptionNew block:^(id observer, id object, NSDictionary *change) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *fullname = [change objectForKey:NSKeyValueChangeNewKey];
if ([fullname isKindOfClass:[NSString class]]) {
if (![weakSelf.fullnameLabel.text isEqualToString: fullname]) {
weakSelf.fullnameLabel.text = fullname;
[weakSelf.fullnameLabel sizeToFit];
}
}
});
}];
This code crashes on the 3rd line NSString *fullname = [change objectForKey:NSKeyValueChangeNewKey];
The crash log is as below:
Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00002069
0 libobjc.A.dylib 0x38449612 objc_retain + 17
1 Retro 0x0013336b __33-[ProfileHeaderView observeUser:]_block_invoke_2491 (ProfileHeaderView.m:598)
2 libdispatch.dylib 0x38922833 _dispatch_call_block_and_release + 10
3 libdispatch.dylib 0x3892281f _dispatch_client_callout + 22
4 libdispatch.dylib 0x3892949f _dispatch_main_queue_callback_4CF$VARIANT$mp + 278
5 CoreFoundation 0x2d83b8f1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
6 CoreFoundation 0x2d83a1c5 __CFRunLoopRun + 1300
7 CoreFoundation 0x2d7a4f0f CFRunLoopRunSpecific + 522
8 CoreFoundation 0x2d7a4cf3 CFRunLoopRunInMode + 106
9 GraphicsServices 0x326ca663 GSEventRunModal + 138
10 UIKit 0x300f016d UIApplicationMain + 1136
11 Retro 0x0007d253 main (main.m:16)
Any idea why it crashed because I can't replicate this on my device (the log is from crash reporter).