What causes apps to crash on resume after a long time in background? - iphone

I'm finding that after my app has been in the background for a while, (half hour + maybe) it crashes immediately on resume.
Crash log reveals that it is EXC_BAD_ACCESS, but I'm at loss for how to debug this one, because I don't know what gets released when my app goes to background (for a long time in particular). (Exception codes are 0x0000000 repeated)
Is there any documentation on this / can anyone give insight about what they did to fix this in the past?
While we're at it, is there a way to test this without waiting for hours before each try? Some way to simulate whatever it is that is happening to my app?
Thanks
Update
I just read a bit more closely, and there's something here about a timer, I added some stuff that uses timers recently to my app, could this give more info? (See item 12)
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x32858a1c __pthread_kill + 8
1 libsystem_c.dylib 0x337013b4 pthread_kill + 52
2 libsystem_c.dylib 0x336f9bf8 abort + 72
3 libstdc++.6.dylib 0x30504a64 __gnu_cxx::__verbose_terminate_handler() + 376
4 libobjc.A.dylib 0x3068f06c _objc_terminate + 104
5 libstdc++.6.dylib 0x30502e36 __cxxabiv1::__terminate(void (*)()) + 46
6 libstdc++.6.dylib 0x30502e8a std::terminate() + 10
7 libstdc++.6.dylib 0x30502f5a __cxa_throw + 78
8 libobjc.A.dylib 0x3068dc84 objc_exception_throw + 64
9 MarsCrash 0x0000be88 0x1000 + 44680
10 MarsCrash 0x00020646 0x1000 + 128582
11 Foundation 0x327196ce __NSFireDelayedPerform + 362
12 CoreFoundation 0x334e7a40 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
13 CoreFoundation 0x334e9ec4 __CFRunLoopDoTimer + 844
14 CoreFoundation 0x334ea83e __CFRunLoopRun + 1082
15 CoreFoundation 0x3347aebc CFRunLoopRunSpecific + 224
16 CoreFoundation 0x3347adc4 CFRunLoopRunInMode + 52
17 GraphicsServices 0x311a5418 GSEventRunModal + 108
18 GraphicsServices 0x311a54c4 GSEventRun + 56
19 UIKit 0x31b90d62 -[UIApplication _run] + 398
20 UIKit 0x31b8e800 UIApplicationMain + 664
21 MarsCrash 0x00002558 0x1000 + 5464
22 MarsCrash 0x00002500 0x1000 + 5376

Common case for such situations is a call to an object that was released due to low memory warnings. EXEC_BAD_ACCESS — accessing to over-release object according to Apple's source (http://developer.apple.com/library/mac/#qa/qa1367/) You can find an actual source of the problem by taking a crash logs from your device and symbolizing it to an actual code strings in your product. I assume that knowing the class and method and code line number will give you a preliminary understanding what goes wrong in your code. Please, review following apple's article to understand further details — http://developer.apple.com/library/ios/#technotes/tn2151/_index.html
For an advanced topics on debugging following link maybe also very useful — http://developer.apple.com/library/ios/#technotes/tn2239/_index.html Actually Apple provides a ton of difference ways to debug such type of an issue.

If it is indeed caused by a memory hit, you can try running it on the simulator, which has a menu item which lets you send your app a simulated memory warning. Your app will try to do all the things it does during a real memory warning, and that might help you find your bug. Also, look at running with NSZombies enabled You might want to check out this page -- I find it very helpful:
http://www.cocoadev.com/index.pl?DebuggingAutorelease

Related

How to fix 'outlined consume of Model?' runtime crash on Swift 5

I just upgraded one of my apps to Swift 5, I didn't change so much at all and there didn't seem to be any problems, so I just released it in production (fortunately in phased release).
After 1 days I started to see a very strange crash on Crashlytics that affect the 15% of people that is using my app.
This is the stack trace:
Crashed: com.apple.main-thread
0 (Missing) 0x31698aa1503e0 (Missing)
1 libswiftCore.dylib 0x1afa5ac68 _swift_release_dealloc + 28
2 App 0x104194c3c outlined consume of MyModel? + 4300033084
3 App 0x104482cb8 #objc MyController.__ivar_destroyer (<compiler-generated>)
4 libobjc.A.dylib 0x180f267cc object_cxxDestructFromClass(objc_object*, objc_class*) + 148
5 libobjc.A.dylib 0x180f366b8 objc_destructInstance + 68
6 libobjc.A.dylib 0x180f36720 object_dispose + 16
7 UIKitCore 0x1ae2edac0 -[UIResponder dealloc] + 152
8 UIKitCore 0x1add173e0 -[UIViewController dealloc] + 1748
9 App 0x10431d82c BaseViewController.__deallocating_deinit (MyController.swift:56)
10 App 0x10431d85c #objc BaseViewController.__deallocating_deinit (<compiler-generated>)
11 libobjc.A.dylib 0x180f41b9c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 672
12 CoreFoundation 0x181d59f40 _CFAutoreleasePoolPop + 28
13 CoreFoundation 0x181cd8e00 __CFRunLoopRun + 1932
14 CoreFoundation 0x181cd8354 CFRunLoopRunSpecific + 436
15 GraphicsServices 0x183ed879c GSEventRunModal + 104
16 UIKitCore 0x1ae2c3b68 UIApplicationMain + 212
17 App 0x104108468 main (AppDelegate.swift:21)
18 libdyld.dylib 0x18179e8e0 start + 4
I searched already something on the web but I find only a thread on the Swift Forum not very related to this.
MyModel is actually a struct model that is nested into another Model.
MyController is the very huge controller that manages the model.
The crash seems to happen obviously when popping the controller and so when the System tries to deallocate all the related properties.
I tried to replicate it many times with no results, and I didn't know really where to start looking.
Someone had the same problem?
UPDATE [Partially Fixed]:
It seemed to be a stack corruption caused by a Advertising Framework, to fix this I moved MyModel from Struct to Class, it's now on the Heap and can't get double freed.
From my experience, most of the outlined consume of errors are caused by concurrency issue. When one queue/thread reading the struct while another queue/thread modifying it without synchronization (mutex, semaphore, barrier, etc).
You need to check all threads stacks to see which thread access MyModel simultaneously with the Main(crashed) thread.

What is UICalloutBarButton, and why does it make my app crash?

I'm going through some of the reported crash reports for my iPhone app, and I'm stumped by the following.
It's very possible it crashes somewhere in my code - it may be an event handler calling the wrong selector somewhere. The problem is I have no idea WHERE this code is - I don't know what a UICalloutBarButton or UICalloutBar is.
Also, needless to say, I can't reproduce this on my end, otherwise it'd be easy to figure out where it's happening.
Date/Time: 2011-03-18 14:33:13.373 +0100
OS Version: iPhone OS 4.3 (8F190)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x317aaa1c __pthread_kill + 8
1 libsystem_c.dylib 0x355593b4 pthread_kill
2 libsystem_c.dylib 0x35551bf8 abort
3 libstdc++.6.dylib 0x33378a64 __gnu_cxx::__verbose_terminate_handler() + 376
4 libobjc.A.dylib 0x364b506c _objc_terminate
5 libstdc++.6.dylib 0x33376e36 __cxxabiv1::__terminate(void (*)()) + 46
6 libstdc++.6.dylib 0x33376e8a std::terminate() + 10
7 libstdc++.6.dylib 0x33376f5a __cxa_throw + 78
8 libobjc.A.dylib 0x364b3c84 objc_exception_throw
9 CoreFoundation 0x354e21b8 -[NSObject(NSObject) doesNotRecognizeSelector:]
10 CoreFoundation 0x354e1642 ___forwarding___
11 CoreFoundation 0x35458178 _CF_forwarding_prep_0 + 40
12 CoreFoundation 0x3544befc -[NSObject(NSObject) performSelector:withObject:]
13 UIKit 0x35e259b2 -[UICalloutBar buttonPressed:]
14 CoreFoundation 0x3544befc -[NSObject(NSObject) performSelector:withObject:]
15 UIKit 0x35e25cd4 -[UICalloutBarButton sendCallback]
16 Foundation 0x31d096ce __NSFireDelayedPerform
17 CoreFoundation 0x354b5a40 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
18 CoreFoundation 0x354b7ec4 __CFRunLoopDoTimer
19 CoreFoundation 0x354b883e __CFRunLoopRun
20 CoreFoundation 0x35448ebc CFRunLoopRunSpecific
21 CoreFoundation 0x35448dc4 CFRunLoopRunInMode
22 GraphicsServices 0x328e8418 GSEventRunModal
23 GraphicsServices 0x328e84c4 GSEventRun
24 UIKit 0x35bffd62 -[UIApplication _run]
25 UIKit 0x35bfd800 UIApplicationMain
26 app name 0x000022d0 main + 36
27 app name 0x0000226c start + 44
UICalloutBar is a UIKit private API.
I think this is the contextual menu that appears on text selection... (Copy/Paste...)
Anyway, this crash really likes coming from internal APIs.
So I guess that it is :
An apple bug (check the iOS versions vs crash occurences)
OR someone with a jailbroken device with dirty extensions/tweaks messing internal APIs
I'm afraid that the chances you find a fix for this are very low. I hope I'm wrong! :)
I had a crash from this API too. I was allowing my tableView to copy cells which displays a context copy menu automatically.
The crash was the result of a user clicking the back button of the navigation bar instead of clicking this menu option. The menu doesn't get dismissed and stays floating on the window until someone taps it. By this time the UITableViewController subclass is popped off the navigation stack resulting in a message being sent to the deallocated instance.
This might be an Apple UIKit bug, I'm not sure. One solution is to dismiss the menu manually in your viewWillDisappear: method.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:animated];
}

Strange Errors resulting in EXC_BAD_ACCESS (SIGSEGV)

Hey Guys,
I know there are about 100.000 thread about EXC_BAD_ACCESS (SIGSEGV) Errors. But no one helped me out. I'm not able to solve my problem myself.
A few hours ago, I duplicated the target of my Xcode Project (a iPhone game) to make a free version. But since this Point I get very strange errors. Sometimes the app works as if nothing happened. But most of the time, I get errors like this:
Running pass 'X86 DAG->DAG Instruction Selection' on function '#gleLLVMVecPrimMultiRender13'
And the stack looks like this:
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x015c6c6f prepareForMethodLookup + 31
1 libobjc.A.dylib 0x015c06ad lookUpMethod + 86
2 libobjc.A.dylib 0x015c081a _class_lookupMethodAndLoadCache + 40
3 libobjc.A.dylib 0x015ceaa3 objc_msgSend + 87
4 Birdy Free 0x0001b46d -[SMApplicationManager dealloc] + 58 (SMApplicationManager.m:226)
5 Foundation 0x00489257 -[NSURLConnection(NSURLConnectionReallyInternal) releaseDelegate] + 57
6 Foundation 0x004891f9 _NSURLConnectionReleaseClient + 68
7 CFNetwork 0x01a45742 ClientContextHolder<CFURLConnectionClient_V4>::forget() + 48
8 CFNetwork 0x01a3beee URLConnectionClient::processEvents() + 278
9 CFNetwork 0x01a3bcb7 MultiplexerSource::perform() + 251
10 CoreFoundation 0x0144e01f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
11 CoreFoundation 0x013ac28b __CFRunLoopDoSources0 + 571
12 CoreFoundation 0x013ab786 __CFRunLoopRun + 470
13 CoreFoundation 0x013ab240 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x013ab161 CFRunLoopRunInMode + 97
15 GraphicsServices 0x02a13268 GSEventRunModal + 217
16 GraphicsServices 0x02a1332d GSEventRun + 115
17 UIKit 0x0086d42e UIApplicationMain + 1160
18 Birdy Free 0x000024a0 main + 82 (main.m:13)
19 Birdy Free 0x00002445 start + 53
But the method called is not always the same. In this case it was [SMApplicationManager dealloc] and a few minutes ago it was [CCNode draw]. I can't get the source of this error. I think it has something to do with the second target.
Do any of you guys know anything more?
Sandro Meier
It's weird i got this error, and i went through countless solutions. Turned out, i had duplicated a line of code by accident. Just make sure when you duplicated, there is not code interfering with each other.
Finally after a few more hours of frustrating experiments I found the solution. The whole thing hadn't to anything with the second target. The Problem was the NSURLConnectionDelegate. In this class I implemented a Property named appID. And in one of the methods of the class, I set the variable without the setter. So I placed an autoreleased object at the position of a property. This one get released and the pointer to the variable gets invalid. As soon as the Delegate was released, a Method was sent to this yet released object.
But I can't explain why there appears this strange error Method. I haven't seen anything like that before. Can someone tell my why the error is called
Running pass 'X86 DAG->DAG Instruction Selection' on function '#gleLLVMVecPrimMultiRender13'?
Sandro Meier
`

How to diagnose a KERN_PROTECTION_FAILURE

I am getting an interesting crash that I can never seem to replicate on the simulator:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000008
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3212e86c 0x3212c000 + 10348
1 StockTwits 0x00016b06 0x1000 + 88838
2 Foundation 0x30718422 0x306db000 + 250914
3 Foundation 0x307183a4 0x306db000 + 250788
4 CFNetwork 0x30933e74 0x30923000 + 69236
5 CFNetwork 0x30927b70 0x30923000 + 19312
6 CFNetwork 0x30927e62 0x30923000 + 20066
7 CFNetwork 0x30927a60 0x30923000 + 19040
8 CFNetwork 0x30927a12 0x30923000 + 18962
9 CFNetwork 0x30927990 0x30923000 + 18832
10 CFNetwork 0x3092790e 0x30923000 + 18702
11 CoreFoundation 0x30352a86 0x302e1000 + 465542
12 CoreFoundation 0x30354768 0x302e1000 + 472936
13 CoreFoundation 0x30355504 0x302e1000 + 476420
14 CoreFoundation 0x302fe8e4 0x302e1000 + 121060
15 CoreFoundation 0x302fe7ec 0x302e1000 + 120812
16 GraphicsServices 0x31a776e8 0x31a74000 + 14056
17 GraphicsServices 0x31a77794 0x31a74000 + 14228
18 UIKit 0x323272a0 0x32321000 + 25248
19 UIKit 0x32325e10 0x32321000 + 19984
20 StockTwits 0x00002fd4 0x1000 + 8148
21 StockTwits 0x00002fa4 0x1000 + 8100
I have NSZombies enabled as well as stack logging. Ran through the static analyzer to make sure all objects are retained and released properly, though I have a feeling it is still related to retain/releasing.
Thoughts?
You must be dereferencing a NULL pointer, other than this crash does not happen. The Static Analyzer is a nice tool for getting hints on things you're doing wrong. However, it not finding an error does not mean that your program is bug-free. Also turning on zombies does not always help. Sometimes it's just a simple little oversight.
The fact the simulator does not show this problem doesn't say too much. In the end it's a different machine with a different processor and a different architecture. There are occasions where false code runs well on one platform but crashes on the other.
You should re-symbolicate you stack trace and have a close look at that function it's crashing in. If you want more help it's probably best to post some of the code here.
One more hint: these issues are often spread over multiple methods. The analyzer only sees one method at a time. You should have a look at what happened to the objects in your crashing method BEFORE it was entered.

Crash invalidates url for NSPersistentStoreCoordinator

I have a Core Data app that has a bug that causes the app to crash and I have not tracked down its cause yet. One of the results of the crash is that the next time the app is started up it can not open the persistent store used by the application previously. The following error is returned from the addPersistentStoreWithType: method:
NSUnderlyingException = Error validating url for store;
And, of course, it cannot retrieve any of the objects previously stored by the app. Does anyone know what can cause an app to no longer be able to find its persistent store?
The crash that causes the app to shut down prior to all this happening produces the following crash log:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x0007e98c __kill + 8
1 libSystem.B.dylib 0x0007e97c kill + 4
2 libSystem.B.dylib 0x0007e96e raise + 10
3 libSystem.B.dylib 0x0009361a abort + 34
4 libstdc++.6.dylib 0x000453b0 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x00005858 _objc_terminate + 104
6 libstdc++.6.dylib 0x00043776 __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x000437ca std::terminate() + 10
8 libstdc++.6.dylib 0x00043896 __cxa_throw + 74
9 libobjc.A.dylib 0x00004714 objc_exception_throw + 64
10 Foundation 0x000013c2 __NSThreadPerformPerform + 570
11 CoreFoundation 0x00056a96 CFRunLoopRunSpecific + 1834
12 CoreFoundation 0x00056356 CFRunLoopRunInMode + 42
13 GraphicsServices 0x00003b2c GSEventRunModal + 108
14 GraphicsServices 0x00003bd8 GSEventRun + 56
15 UIKit 0x00002768 -[UIApplication _run] + 384
16 UIKit 0x0000146c UIApplicationMain + 688
17 Meetchu 0x00002568 main (main.m:14)
18 Meetchu 0x0000251c start + 32
I cannot figure out what is happening from this information. Can anyone help with either of these errors?
Many thanks in advance.
If you're storing the actual URL to a file in the app's directory instead of regenerating it each time relative to the app directory, then the invalid URL is the result of the simulator/device changing the name of the app directory to a random UUID. It does that sometimes in response to crashes.
The obvious first step is the log the URL and see if the store is actually at that location.
Drew,
Without seeing some code, I can tell you that one source of agony to me when I first started with Core Data was versioning your models. If you have changed your managed object model in any way, this will cause your app to crash without some versioning (i.e., lightweight) code in place.
This may not be the source of your problem, but one thing you can try is to either remove your app from your iPhone Simulator or use "Reset Contents and Settings" from the iPhone simulator menu. If this fixes the problem, then you're looking at a migrations issue.
Cheers.