Strange Crash issue as:- Dispatch queue: com.apple.root.default-overcommit-priority - objective-c

I am developing an application in which a lot of operations are added in ASINetworkQueue.The operations are basically used for fetching the image from server and then in successful completion set the image in table view cell.
Everything is happening fine.I have a button a table view cell on which another view controller gets opened.
On that another view there is a cross button on which I pop that view controller.
Now when the cross button gets clicked sometimes the app gets crashed there, sometimes it gets crashes when comes back to the previous view and scrolling my table view.
When I see the crash logs I found that the following code comes in whatever the thread crashed.Sometime it is crashed thread2 ,sometime it is crashed thread 12, sometime it is crashed thread 6 but the code inside that thread is same which is shown below.
Thread 11 name: Dispatch queue: com.apple.root.default-overcommit-priority
Thread 11 Crashed:
0 Foundation 0x357320b2 0x3569e000 + 606386
1 Foundation 0x356add56 0x3569e000 + 64854
2 Foundation 0x356adb94 0x3569e000 + 64404
3 Foundation 0x35731f48 0x3569e000 + 606024
4 Foundation 0x356add56 0x3569e000 + 64854
5 Foundation 0x356adb94 0x3569e000 + 64404
6 Foundation 0x35731ebc 0x3569e000 + 605884
7 libdispatch.dylib 0x3698c9f6 0x36981000 + 47606
8 libdispatch.dylib 0x3698f21e 0x36981000 + 57886
9 libdispatch.dylib 0x3698cb70 0x36981000 + 47984
10 libdispatch.dylib 0x3698d76c 0x36981000 + 51052
11 libsystem_c.dylib 0x32af91c8 0x32aef000 + 41416
12 libsystem_c.dylib 0x32af909c 0x32aef000 + 41116
I am stuck here as the crash log is not getting symolicated also and also it is happening on some devices not on every device.
Please suggest me how to solve this strange crash issue.
Any suggestions would be highly appreciated.
Thanks in advance.Please Please help me.

I cannot talk to the exact technical reason that this is happening, but I had this error today. It occurred only on iPad 1 and it turned out to be related to trying to scale a huge image (which I thought was smaller). Reducing the size of the image removed the com.apple.root.default-overcommit-priority error.
So it's probably memory related (particularly low memory).

Related

How to easily investigate 'This application is modifying the autolayout engine from a background thread' [duplicate]

Been encountering this error a lot in my OS X using swift:
"This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release."
I have a my NSWindow and I'm swapping in views to the contentView of the window. I get the error when I try and do a NSApp.beginSheet on the window, or when I add a subview to the window. Tried disabling autoresize stuff, and I don't have anything using auto layout. Any thoughts?
Sometimes it's fine and nothing happens, other times it totally breaks my UI and nothing loads
It needs to be placed inside a different thread that allows the UI to update as soon as execution of thread function completes:
Modern Swift:
DispatchQueue.main.async {
// Update UI
}
Older versions of Swift, pre Swift 3.
dispatch_async(dispatch_get_main_queue(){
// code here
})
Objective-C:
dispatch_async(dispatch_get_main_queue(), ^{
// code here
});
You get similar error message while debugging with print statements without using 'dispatch_async'
So when you get that error message, its time to use
Swift 4
DispatchQueue.main.async { //code }
Swift 3
DispatchQueue.main.async(){ //code }
Earlier Swift versions
dispatch_async(dispatch_get_main_queue()){ //code }
The "this application is modifying the autolayout engine from a background thread" error is logged in the console long after the actual problem occured, so debugging this can be hard without using a breakpoint.
I used #markussvensson's answer to detect my problem and found it using this Symbolic Breakpoint (Debug > Breakpoints > Create Symbolic Breakpoint):
Symbols: [UIView layoutIfNeeded] or [UIView updateConstraintsIfNeeded]
Condition: !(BOOL)[NSThread isMainThread]
Build and run the app on the emulator and replicate the steps that lead to the error message being thrown (the app will be slower than usual!). Xcode will then stop the app and mark the line of code (e.g. the call of a func) that's accessing the UI from a background thread.
When you try to update a text field value or adding a subview inside a background thread, you can get this problem. For that reason, you should put this kind of code in the main thread.
You need to wrap methods that call UI updates with dispatch_asynch to get the main queue. For example:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.friendLabel.text = "You are following \(friendCount) accounts"
})
EDITED - SWIFT 3:
Now, we can do that following the next code:
// Move to a background thread to do some long running work
DispatchQueue.global(qos: .userInitiated).async {
// Do long running task here
// Bounce back to the main thread to update the UI
DispatchQueue.main.async {
self.friendLabel.text = "You are following \(friendCount) accounts"
}
}
For me, this error message originated from a banner from Admob SDK.
I was able to track the origin to "WebThread" by setting a conditional breakpoint.
Then I was able to get rid of the issue by encapsulating the Banner creation with:
dispatch_async(dispatch_get_main_queue(), ^{
_bannerForTableFooter = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
...
}
I don't know why this helped as I cannot see how this code was called from a non-main-thread.
Hope it can help anyone.
I had this problem since updating to the iOS 9 SDK when I was calling a block that did UI updates within an NSURLConnection async request completion handler. Putting the block call in a dispatch_async using dispatch_main_queue solved the issue.
It worked fine in iOS 8.
Had the same problem because I was using performSelectorInBackground.
Main problem with "This application is modifying the autolayout engine from a background thread" is that it seem to be logged a long time after the actual problem occurs, this can make it very hard to troubleshoot.
I managed to solve the issue by creating three symbolic breakpoints.
Debug > Breakpoints > Create Symbolic Breakpoint...
Breakpoint 1:
Symbol: -[UIView setNeedsLayout]
Condition: !(BOOL)[NSThread isMainThread]
Breakpoint 2:
Symbol: -[UIView layoutIfNeeded]
Condition: !(BOOL)[NSThread isMainThread]
Breakpoint 3:
Symbol: -[UIView updateConstraintsIfNeeded]
Condition: !(BOOL)[NSThread isMainThread]
With these breakpoints, you can easily get a break on the actual line where you incorrectly call UI methods on non-main thread.
You must not change the UI offside the main thread! UIKit is not thread safe, so that above problem and also some other weird problems will arise if you do that. The app can even crash.
So, to do the UIKit operations, you need to define block and let it be executed on the main queue: such as,
NSOperationQueue.mainQueue().addOperationWithBlock {
}
Obviously you are doing some UI update on back ground thread. Cant predict exactly where, without seeing your code.
These are some situations it might happen:-
you might be doing something on background thread and not using. Being in the same function this code is easier to spot.
DispatchQueue.main.async { // do UI update here }
calling a func doing web request call on background thread and its completion handler calling other func doing ui update.
to solve this try checking code where you have updated the UI after webrequest call.
// Do something on background thread
DispatchQueue.global(qos: .userInitiated).async {
// update UI on main thread
DispatchQueue.main.async {
// Updating whole table view
self.myTableview.reloadData()
}
}
I had this issue while reloading data in UITableView. Simply dispatching reload as follows fixed the issue for me.
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
I had the same problem. Turns out I was using UIAlerts that needed the main queue. But, they've been deprecated.
When I changed the UIAlerts to the UIAlertController, I no longer had the problem and did not have to use any dispatch_async code. The lesson - pay attention to warnings. They help even when you don't expect it.
You already have the correct code answer from #Mark but, just to share my findings:
The issue is that you are requesting a change in the view and assuming that it will happen instantly. In reality, the loading of a view depends on the available resources. If everything loads quickly enough and there are no delays then you don't notice anything. In scenarios, where there is any delay due to the process thread being busy etc, the application runs into a situation where it is supposed to display something even though its not ready yet. Hence, it is advisable to dispatch these requests in a asynchronous queues so, they get executed based on the load.
I had this issue when I was using TouchID if that helps anyone else, wrap your success logic which likely does something with the UI in the main queue.
It could be something as simple as setting a text field / label value or adding a subview inside a background thread, which may cause a field's layout to change. Make sure anything you do with the interface only happens in the main thread.
Check this link: https://forums.developer.apple.com/thread/7399
I had the same issue when trying to update error message in UILabel in the same ViewController (it takes a little while to update data when trying to do that with normal coding). I used DispatchQueue in Swift 3 Xcode 8 and it works.
If you want to hunt this error, use the main thread checker pause on issues checkbox.
Fixing it is easy most of the times, dispatching the problematic line in the main queue.
For me the issue was the following.
Make sure performSegueWithIdentifier: is performed on the main thread:
dispatch_async (dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:#"ViewController" sender:nil];
});
Swift 4,
Suppose, if you are calling some method using operation queue
operationQueue.addOperation({
self.searchFavourites()
})
And suppose function searchFavourites is like,
func searchFavourites() {
DispatchQueue.main.async {
//Your code
}
}
if you call, all code inside the method "searchFavourites" on the main thread, it will still give an error if you are updating some UI in it.
This application is modifying the autolayout engine from a background
thread after the engine was accessed from the main thread.
So use solution,
operationQueue.addOperation({
DispatchQueue.main.async {
self.searchFavourites()
}
})
For this kind of scenario.
Here check out this line from the logs
$S12AppName18ViewControllerC11Func()ySS_S2StF + 4420
you can check that which function calling from the either background thread or where you are calling api method you need to call your function from the main thread like this.
DispatchQueue.main.async { func()}
func() is that function you want to call in the result of api call
success or else.
Logs Here
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
Stack:(
0 Foundation 0x00000001c570ce50 <redacted> + 96
1 Foundation 0x00000001c5501868 <redacted> + 32
2 Foundation 0x00000001c5544370 <redacted> + 540
3 Foundation 0x00000001c5543840 <redacted> + 396
4 Foundation 0x00000001c554358c <redacted> + 272
5 Foundation 0x00000001c5542e10 <redacted> + 264
6 UIKitCore 0x00000001f20d62e4 <redacted> + 488
7 UIKitCore 0x00000001f20d67b0 <redacted> + 36
8 UIKitCore 0x00000001f20d6eb0 <redacted> + 84
9 Foundation 0x00000001c571d124 <redacted> + 76
10 Foundation 0x00000001c54ff30c <redacted> + 108
11 Foundation 0x00000001c54fe304 <redacted> + 328
12 UIKitCore 0x00000001f151dc0c <redacted> + 156
13 UIKitCore 0x00000001f151e0c0 <redacted> + 152
14 UIKitCore 0x00000001f1514834 <redacted> + 868
15 UIKitCore 0x00000001f1518760 <redacted> + 104
16 UIKitCore 0x00000001f1543370 <redacted> + 1772
17 UIKitCore 0x00000001f1546598 <redacted> + 120
18 UIKitCore 0x00000001f14fc850 <redacted> + 1452
19 UIKitCore 0x00000001f168f318 <redacted> + 196
20 UIKitCore 0x00000001f168d330 <redacted> + 144
21 AppName 0x0000000100b8ed00 $S12AppName18ViewControllerC11Func()ySS_S2StF + 4420
22 AppName 0x0000000100b8d9f4 $S12CcfU0_y10Foundation4DataVSg_So13NSURLResponseCSgs5Error_pSgtcfU_ + 2384
23 App NAme 0x0000000100a98f3c $S10Foundation4DataVSgSo13NSURLResponseCSgs5Error_pSgIegggg_So6NSDataCSgAGSo7NSErrorCSgIeyByyy_TR + 316
24 CFNetwork 0x00000001c513aa00 <redacted> + 32
25 CFNetwork 0x00000001c514f1a0 <redacted> + 176
26 Foundation 0x00000001c55ed8bc <redacted> + 16
27 Foundation 0x00000001c54f5ab8 <redacted> + 72
28 Foundation 0x00000001c54f4f8c <redacted> + 740
29 Foundation 0x00000001c55ef790 <redacted> + 272
30 libdispatch.dylib 0x000000010286f824 _dispatch_call_block_and_release + 24
31 libdispatch.dylib 0x0000000102870dc8 _dispatch_client_callout + 16
32 libdispatch.dylib 0x00000001028741c4 _dispatch_continuation_pop + 528
33 libdispatch.dylib 0x0000000102873604 _dispatch_async_redirect_invoke + 632
34 libdispatch.dylib 0x00000001028821dc _dispatch_root_queue_drain + 376
35 libdispatch.dylib 0x0000000102882bc8 _dispatch_worker_thread2 + 156
36 libsystem_pthread.dylib 0x00000001c477917c _pthread_wqthread + 472
37 libsystem_pthread.dylib 0x00000001c477bcec start_wqthread + 4
)
I also encountered this problem, seeing a ton of these messages and stack traces being printed in the output, when I resized the window to a smaller size than its initial value. Spending a long time figuring out the problem, I thought I'd share the rather simple solution. I had once enabled Can Draw Concurrently on an NSTextView through IB. That tells AppKit that it can call the view's draw(_:) method from another thread. After disabling it, I no longer got any error messages. I didn't experience any problems before updating to macOS 10.14 Beta, but at the same time, I also started modifying the code to perform work with the text view.

Tracking down a SIGSEGV…

So I've got this weird SIGSEGV happening at very few (less than 1%) of my users…
From the stack trace it looks like an over-release
Thread 0 Crashed:
0 libobjc.A.dylib 0x00007fff9a3f916f objc_release + 31
1 libobjc.A.dylib 0x00007fff9a3f7ac4 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 475
2 CoreFoundation 0x00007fff9cc5c102 _CFAutoreleasePoolPop + 49
3 Foundation 0x00007fff96992cb6 -[NSAutoreleasePool drain] + 152
4 AppKit 0x00007fff9138409b -[NSApplication run] + 892
5 AppKit 0x00007fff91306520 NSApplicationMain + 1175
6 RailModeller Pro 0x000000010b60578b main (main.m:30)
7 libdyld.dylib 0x00007fff9a36b5ad start + 0
..but no matter what I try,
even with the very same data,
following the exact same steps as the users,
same OS/patch level,
using Address Sanitizer (Xcode 7.3),
using Zombies instrument,
using Guard Malloc
all appears to be fine.
The function crashing is a pretty common one in the app and I'd be drowning in bug reports (both from the automated bug reporting system as well as users getting in touch) if this were a more common issue.
However, to these (<1%) users the app appears effectively unusable.
Any hints on how to track down this issue much appreciated!

Old iOS6 app is now crashing when trying to open in iOS8

I'm trying to fix a legacy app (hasn't been updated to iOS7 or above. Still shows iOS6 UI). Whenever the app tries to open, it crashes. I found the problem at the didFinishLaunchingWithOptions method when I set the tab bar controller.
[self.window setRootViewController:self.tabBarController];
I get this error:
CRASH: *** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
This is the Stack Trace:
2014-09-27 01:08:35.517 AppName[2919:1348769] Stack Trace: (
0 CoreFoundation 0x233dde57 <redacted> + 150
1 libobjc.A.dylib 0x30a8bc8b objc_exception_throw + 38
2 CoreFoundation 0x232f2e9d CFRunLoopRemoveTimer + 0
3 AppName 0x000940eb -[NSArray(UtilityExtensions) firstObject] + 46
4 UIKit 0x2694a93d <redacted> + 400
5 UIKit 0x269b869f <redacted> + 254
6 AppName 0x00137fa3 -[FirstChildViewController viewWillAppear:] + 126
So I understand that bug to be something where its assumed I'm trying to access an item in an array where none exists. But the tab controller shows a count of all the view controllers it should have. So Any help would be greatly appreciated.
Again, this ONLY happens when I try to build and run for iOS8.
Thanks in advance!

where to look for a bug. document, app delegate or both?

following situation: i have a document based App. by default when i open the app it displays just the menu on top of the screen. then i hit file->new and it opens up a brand new document.xib interface. working fine on my main pc. but on my secodnary pc running 10.6.8 the app crashes as soon as i run it. (code is compiled with the proper target...)
this application is crashing BEFORE i even see the main menu at the top. could the cause of the crash still be inside the document's xib file? or will it most likely be in the code that is outside the document part? what i mean is: is the code checked completely at the application lounch or does it onyl cause a crash when it reaches the code that is causing it?
thanks
edit
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 ??? 000000000000000000 0 + 0
1 com.apple.AppKit 0x0000000100def22e -[NSCustomObject nibInstantiate] + 416
2 com.apple.AppKit 0x0000000100def01b -[NSIBObjectData instantiateObject:] + 259
3 com.apple.AppKit 0x0000000100dee406 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 336
4 com.apple.AppKit 0x0000000100deca91 loadNib + 226
5 com.apple.AppKit 0x0000000100debfa1 +[NSBundle(NSNibLoading)_loadNibFile:nameTable:withZone:ownerBundle:] + 248
6 com.apple.AppKit 0x0000000100debdd9 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 326
7 com.apple.AppKit 0x0000000100de935b NSApplicationMain + 279
8 mad-sharky.com.Stockuploader 0x0000000100001194 0x100000000 + 4500
The problem lies not in the XIB file, but rather in one of the objects in said file that is being instantiated incorrectly. Something about the object is causing it's -initWithCoder: method to fail. It appears you're probably not calling through to super in said method, and are simply returning self, which is not allowed.
The other possibility is that you have a "ghost outlet". Sometimes, when an IBOutlet is created and linked, then the piece of code that declares it is removed, IB doesn't de-link the outlet, and NSCoder tries to dearchive a nil outlet.
found the problem. here it is:
now it works without any problems!

CorePlot MonoMac bindings crashing

I am trying to use the CorePlot 0.9 binding for monomac, but that seems to be a hard task. The monotouch sample builds and runs without any problems, but I don't need that one.
Since only a CorePlotiOS.dll was present in the binding, I had to build one for osx myself, but first of af all, no bmake.exe was present, so I had to download the monomac source and build it myself first. Then I tried to build the CorePlotOSX.dll but that caused some compilation problems. Looking at the build-script for mono touch I tried with this line instead:
MONO_PATH=$(MONOMAC)/src mono $(MONOMAC)/src/bmac.exe -e -unsafe coreplot.cs -s=enums.cs -x=extras.cs -x=AssemblyInfo.cs --sourceonly=list --tmpdir=osx -r:System.Drawing -r:MonoMac -lib:$(MONOMAC)/src -baselib:$(MONOMAC)/src/MonoMac.dll .
Anything wrong there?
I have reduced the problem to this:
graph = new CPTPieChart();
graph.Title = "Test";
The allocation seems to survive, but whenever I try to access the object, I crash:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000bf887fac
VM Regions Near 0xbf887fac:
Stack 00000000b038d000-00000000b040e000 [ 516K] rw-/rwx SM=COW
--> Stack 00000000bc088000-00000000bf888000 [ 56.0M] ---/rwx SM=NUL
Stack 00000000bf888000-00000000c0088000 [ 8192K] rw-/rwx SM=COW
Application Specific Information:
objc[17645]: garbage collection is OFF
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x97c8aebc __CFStringEncodeByteStream + 12
1 com.apple.Foundation 0x9ac8ed49 -[NSString(NSStringOtherEncodings) getBytes:maxLength:usedLength:encoding:options:range:remainingRange:] + 263
2 com.apple.Foundation 0x9ac8e8ee bytesInEncoding + 213
3 com.apple.Foundation 0x9ac8e814 -[NSString(NSStringOtherEncodings) UTF8String] + 42
4 com.apple.CoreFoundation 0x97ce478c -[__NSCFString UTF8String] + 204
5 ??? 0x00f91208 0 + 16323080
6 ??? 0x030d708c 0 + 51212428
7 ??? 0x030d703c 0 + 51212348
8 ??? 0x016877d4 0 + 23623636
Any ideas? Running Mac OSX 10.7.5 btw.
Ok, that was hard. After several days of fighting xcode and monomac, it turned out, that the native CorePlot framework (dynamic lib) was not loaded. I was not aware, that I was supposed to load it myself (I am a monomac newbie, sorry...but isn't it rather ugly it fails silently in that way??)
Two ways to do this: either
Dlfcn.dlopen ("CorePlot.framework/CorePlot", 2); // 2 = load now, 0 = lazy load
or [assembly:MonoMac.RequiredFramework("CorePlot.framework/CorePlot")]