Cocoa archived app crashing - swift

I am new in archiving app for testing/distribution. My MacOS cocoa app crash only when built as an archive.
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: exc handler [0]
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 MY.APP 0x000000010100532a specialized String._CharacterView.index(after:) + 250
1 MY.APP 0x0000000100f55ef9 specialized static TextCompletionNode.hasCommonPrefix(_:with:beyond:) + 153 (AttributeManager.swift:126)
2 MY.APP 0x0000000100f571f9 specialized TextCompletionNode.add(entry:for:) + 1161
3 MY.APP 0x0000000100f584a9 specialized closure #1 in AttributeManager.init(dataSource:loadingHandler:) + 3097
4 MY.APP 0x0000000100f5439e partial apply for closure #1 in AttributeManager.init(dataSource:loadingHandler:) + 30
5 MY.APP 0x000000010104d0a3 SearchQueryCommunicator.messageHandler(_:) + 451
6 MY.APP 0x000000010104d710 protocol witness for MessageHandler.messageHandler(_:) in conformance SearchQueryCommunicator + 16
7 MY.APP 0x000000010102ede8 Socket.handle(object:) + 456
8 MY.APP 0x0000000101031928 specialized Socket.readAvailableBytes(from:) + 1096
9 MY.APP 0x0000000101031c48 specialized Socket.stream(_:handle:) + 104 (Socket.swift:77)
10 MY.APP 0x000000010102ebff #objc Socket.stream(_:handle:) + 47
11 com.apple.CoreFoundation 0x00007fff49548dc4 _signalEventSync + 228
12 com.apple.CoreFoundation 0x00007fff49563736 _cfstream_solo_signalEventSync + 246
13 com.apple.CoreFoundation 0x00007fff49546ca4 _CFStreamSignalEvent + 484
14 com.apple.CFNetwork 0x00007fff48448a62 SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) + 58
15 com.apple.CFNetwork 0x00007fff4844cff9 SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) + 145
16 com.apple.CFNetwork 0x00007fff4844cf2e SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 70
17 com.apple.CoreFoundation 0x00007fff49546898 __CFSocketPerformV0 + 1016
18 com.apple.CoreFoundation 0x00007fff49527a11 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 com.apple.CoreFoundation 0x00007fff495e142c __CFRunLoopDoSource0 + 108
20 com.apple.CoreFoundation 0x00007fff4950a470 __CFRunLoopDoSources0 + 208
21 com.apple.CoreFoundation 0x00007fff495098ed __CFRunLoopRun + 1293
22 com.apple.CoreFoundation 0x00007fff49509153 CFRunLoopRunSpecific + 483
23 com.apple.HIToolbox 0x00007fff487f3d96 RunCurrentEventLoopInMode + 286
24 com.apple.HIToolbox 0x00007fff487f3b06 ReceiveNextEventCommon + 613
25 com.apple.HIToolbox 0x00007fff487f3884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
26 com.apple.AppKit 0x00007fff46aa4a73 _DPSNextEvent + 2085
27 com.apple.AppKit 0x00007fff4723ae34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
28 com.apple.AppKit 0x00007fff46a99885 -[NSApplication run] + 764
29 com.apple.AppKit 0x00007fff46a68a72 NSApplicationMain + 804
30 MY.APP 0x0000000100f40949 main + 9 (AppDelegate.swift:12)
31 libdyld.dylib 0x00007fff7134a015 start + 1
Here's the TextCompletionNode function:
// we assume firstString and secondString are at least longer than beyond
private static func hasCommonPrefix(_ firstString:String, with secondString:String, beyond beyondIndex:String.Index) -> String? {
assert((firstString.endIndex >= beyondIndex) && (secondString.endIndex >= beyondIndex))
var commonPrefix = String(firstString[..<beyondIndex])
guard secondString.hasPrefix(commonPrefix) else {
return nil
}
var firstIndex = beyondIndex
let firstEndIndex = firstString.endIndex
var previousCommonPrefix: String
repeat {
previousCommonPrefix = commonPrefix
if firstIndex >= firstEndIndex {
break
}
//NSLog("firstString = \"\(firstString)\", firstIndex = \(firstIndex)")
firstIndex = firstString.index(after: firstIndex) // <-- Crashing?
commonPrefix = String(firstString[..<firstIndex])
} while secondString.hasPrefix(commonPrefix)
return previousCommonPrefix
}
Everything is working well when testing the same functionality when running the app from Xcode. I've read that debugging information is removed from archived app so you can't really debug them. I've tried to add a NSLog statement to write some debugging information in the Console app, and nothing is showing. I also tried starting the app from command-line (MyApp.app/Contents/MacOS/MyApp), nothing is showing in the terminal either.
I would like to know more about the conditions before the crash. What should I do?
EDIT: I've tried to flush STDERR and even redirect STDERR into a file based on this answer from this other post: https://stackoverflow.com/a/5938021/301189 and nothing was working. Simply replacing NSLog(_:_:) with printf(_:) helped me to get some output in the terminal. I still don't know why I can't get anything from STDERR in the archived app though.
Also, the above crash does not happen when putting output some output in the terminal. Such a weird bug...

Related

Crash in IMKKit composedString(_:) using swift

I am writing a swift input method (IM) using InputMethodKit. The IM basically works, I get keystrokes from inputText() and see my log messages in Konsole.
Now I implement composedString(_ sender: Any!) in swift like this:
override func composedString(_ sender: Any!) -> Any! {
let ret = NSMutableString().append("test")
return ret
}
I understand that composedString(_ sender: Any!) is called by the system when I call updateComposition(). This is indeed the case but composedString(_ sender: Any!) does crash showing that output:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x00007fff2ccbd680 swift_unknownObjectRetain + 32
1 com.IBNSoft.inputmethod.MyApp 0x000000010c08c491 #objc InputController.composedString(_:) + 33
2 com.apple.InputMethodKit 0x00007fff4670358d -[IMKInputController updateComposition] + 45
3 com.IBNSoft.inputmethod.MyApp 0x000000010c08a5bf closure #1 in InputController.inputText(_:client:) + 703 (InputController.swift:25)
4 com.IBNSoft.inputmethod.MyApp 0x000000010c086740 thunk for #escaping #callee_guaranteed () -> () + 48
5 libdispatch.dylib 0x00007fff20441603 _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x00007fff204427e6 _dispatch_client_callout + 8
7 libdispatch.dylib 0x00007fff2044eb2f _dispatch_main_queue_callback_4CF + 940
8 com.apple.CoreFoundation 0x00007fff207226f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
9 com.apple.CoreFoundation 0x00007fff206e48e2 __CFRunLoopRun + 2755
10 com.apple.CoreFoundation 0x00007fff206e375c CFRunLoopRunSpecific + 563
11 com.apple.HIToolbox 0x00007fff28905203 RunCurrentEventLoopInMode + 292
12 com.apple.HIToolbox 0x00007fff28904f65 ReceiveNextEventCommon + 587
13 com.apple.HIToolbox 0x00007fff28904d03 _BlockUntilNextEventMatchingListInModeWithFilter + 70
14 com.apple.AppKit 0x00007fff22edfb32 _DPSNextEvent + 864
15 com.apple.AppKit 0x00007fff22ede305 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
16 com.apple.AppKit 0x00007fff22ed0679 -[NSApplication run] + 586
17 com.apple.AppKit 0x00007fff22ea485c NSApplicationMain + 816
18 com.IBNSoft.inputmethod.MyApp 0x000000010c08935d main + 13 (AppDelegate.swift:19)
19 libdyld.dylib 0x00007fff20607f3d start + 1
The Apple docs say about composedString(_:):
Return Value:
The current composed string, which can be an NSString or
NSAttributedString object. The returned object should be an
autoreleased object.
I guess the problem is that I don't allocate the NSMutableString correctly with respect to "autorelease and retain". Can anybody shed light what the problem with that crash is an how to solve it.
Thanks

NSOutlineView crash on Mac OS versions below 10.12 as 'stronglyReferencesItems' set to 'false' by default

My app has an outline view which get frequent updates from server. Whenever I get an update I reload outline view. I do multiple operation with outline at the same time like showing some buttons on mouse over, expand/collapse items. For these operations I get item from outline view with NSOutlineView.item(atRow:)
The issue is, at random scenarios my app is getting crashed with EXC_BAD_ACCESS (SIGSEGV) in areas where NSOutlineView internally calls NSTableViewdelegate methods on OS versions below 10.12. I know NSOutlineView has its own retain and release cycles for the items from OS version 10.12 as stronglyReferencesItems set to true by default. so the crashes not happening above 10.12.
So how can I resolve this issue? Can some one guide me how to do manual retain and release of items passed to NSOutlineView on lower versions.
Simply put I need to enable the behaviour of stronglyReferencesItems set to true in versions below 10.12.
Note: as I said above I do complex operations with NSOutlineView like move over events, expand/collapse (expanding all the items in some scenarios), reloading the list with frequent updates from server. So mentioning my code here would be complex.
Below is one of the crash logs for your reference:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x000000010c5cec51 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 33
1 libswiftCore.dylib 0x000000010c5ab842 _swift_retain_n_(swift::HeapObject*, unsigned int) + 66
2 libswiftCore.dylib 0x000000010c5f7ac8 swift_bridgeObjectRetain_n + 104
3 com.prosoftnet.remotepcSuite 0x000000010bc8c626 RPCHostGroupTableCellView.setupView(group:) (in RemotePCSuite) (RPCHostGroupTableCellView.swift:0)
4 com.prosoftnet.remotepcSuite 0x000000010bd61198 RPCHostListViewController.outlineView(_:viewFor:item:) (in RemotePCSuite) (RPCHostListViewController.swift:579)
5 com.prosoftnet.remotepcSuite 0x000000010bd61a10 #objc RPCHostListViewController.outlineView(_:viewFor:item:) (in RemotePCSuite) (<compiler-generated>:0)
6 com.apple.AppKit 0x00007fff8f19e0d0 -[NSTableView(NSTableViewViewBased) makeViewForTableColumn:row:] + 76
7 com.apple.AppKit 0x00007fff8f19d541 -[NSTableRowData _addViewToRowView:atColumn:row:] + 300
8 com.apple.AppKit 0x00007fff8f19d27a -[NSTableRowData _addViewsToRowView:atRow:] + 184
9 com.apple.AppKit 0x00007fff8f19b9ad -[NSTableRowData _initializeRowView:atRow:] + 373
10 com.apple.AppKit 0x00007fff8f19aad2 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 396
11 com.apple.AppKit 0x00007fff8f23a9d1 -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 254
12 com.apple.AppKit 0x00007fff8f23a7a3 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 1856
13 com.apple.AppKit 0x00007fff8f239fc7 -[NSTableRowData updateVisibleRowViews] + 230
14 com.apple.AppKit 0x00007fff8f23fe82 -[NSTableView viewWillDraw] + 178
15 com.apple.AppKit 0x00007fff8f2bd83f -[NSOutlineView viewWillDraw] + 169
16 com.apple.AppKit 0x00007fff8f0e6fa1 -[NSView(NSInternal) _sendViewWillDrawAndRecurse:] + 535
17 com.apple.AppKit 0x00007fff8f058ae1 -[NSView(NSLayerKitGlue) _layoutSublayersOfLayer:] + 142
18 com.apple.QuartzCore 0x00007fff8dd79404 -[CALayer layoutSublayers] + 219
19 com.apple.AppKit 0x00007fff8f058a3c _NSBackingLayerLayoutSublayers + 158
20 com.apple.QuartzCore 0x00007fff8dd78fe8 CA::Layer::layout_if_needed(CA::Transaction*) + 366
21 com.apple.QuartzCore 0x00007fff8dd78e66 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
22 com.apple.QuartzCore 0x00007fff8dd78602 CA::Context::commit_transaction(CA::Transaction*) + 242
23 com.apple.QuartzCore 0x00007fff8dd7839e CA::Transaction::commit() + 390
24 com.apple.QuartzCore 0x00007fff8dd86f09 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 71
25 com.apple.CoreFoundation 0x00007fff99bdaf47 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
26 com.apple.CoreFoundation 0x00007fff99bdaea0 __CFRunLoopDoObservers + 368
27 com.apple.CoreFoundation 0x00007fff99bcca18 CFRunLoopRunSpecific + 328
28 com.apple.HIToolbox 0x00007fff8eb4256f RunCurrentEventLoopInMode + 235
29 com.apple.HIToolbox 0x00007fff8eb422ea ReceiveNextEventCommon + 431
30 com.apple.HIToolbox 0x00007fff8eb4212b _BlockUntilNextEventMatchingListInModeWithFilter + 71
31 com.apple.AppKit 0x00007fff8f08a8ab _DPSNextEvent + 978
32 com.apple.AppKit 0x00007fff8f089e58 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
33 com.apple.AppKit 0x00007fff8f07faf3 -[NSApplication run] + 594
34 com.apple.AppKit 0x00007fff8effc244 NSApplicationMain + 1832
35 com.prosoftnet.remotepcSuite 0x000000010bc519a9 main (in RemotePCSuite) (AppDelegate.swift:12)
36 libdyld.dylib 0x00007fff8e4b95c9 start + 1
You could retain the items in an array when they get first referenced from the table in the below method
var items = [ItemType]()
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?)
{
let item = getItem()
items.append(item)
return item
}
Your gonna run into trouble with not know when you can release them though. Youll have to manually handle that logic

Swift - Editing UITextView from inside callback crashes app

I have the following code that makes a HTTP Request, then outputs the result to a UITextView:
#IBOutlet var echoLog: UITextView!
#IBAction func sendEcho(sender: AnyObject) {
let callback = { (textString: String) -> Void in
self.echoLog.text = textString // App crashes here :(
}
HTTPRequest("http://localhost/echo", ["echo": "Echo!"], callback)
}
But when I call sendEcho the app crashes with this error:
2014-07-28 20:58:22.218 AppName[10463:144343] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /SourceCache/UIFoundation_Sim/UIFoundation-364/UIFoundation/TextSystem/NSLayoutManager_Private.m:1547
2014-07-28 20:58:22.231 AppName[10463:144343] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00496ca6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01df08bf objc_exception_throw + 44
2 CoreFoundation 0x00496b3a +[NSException raise:format:arguments:] + 138
3 Foundation 0x00904d2e -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 102
4 UIFoundation 0x03344072 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 418
5 UIFoundation 0x03343d6e -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2017
6 UIFoundation 0x0337da43 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 871
7 UIFoundation 0x0337db53 -[NSLayoutManager processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:] + 85
8 UIFoundation 0x033a7a7b -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 153
9 UIFoundation 0x033a759a -[NSTextStorage processEditing] + 458
10 UIFoundation 0x033a7124 -[NSTextStorage endEditing] + 80
11 UIFoundation 0x033a71af -[NSTextStorage coordinateEditing:] + 67
12 UIKit 0x014938ae -[UITextView setAttributedText:] + 250
13 UIKit 0x01499745 -[UITextView setText:] + 149
14 AppName 0x00036216 _TFFC8AppName19FirstViewController8sendEchoFS0_FPSs9AnyObject_T_U_FOS_9JSONValueT_ + 1350
15 AppName 0x0003525a _TPA__TFFC8AppName19FirstViewController8sendEchoFS0_FPSs9AnyObject_T_U_FOS_9JSONValueT_ + 106
16 AppName 0x0001de86 _TFF8AppName11HTTPRequestFTSSGVSs10DictionarySSPSs9AnyObject__FOS_9JSONValueT__T_U_FTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError__T_ + 1350
17 AppName 0x0001d0a4 _TPA__TFF8AppName11HTTPRequestFTSSGVSs10DictionarySSPSs9AnyObject__FOS_9JSONValueT__T_U_FTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError__T_ + 100
18 AppName 0x0001e289 _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 41
19 AppName 0x0001d15a _TPA__TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 90
20 AppName 0x0001e2d7 _TTRXFo_iTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError___iT__XFo_oGSQS__oGSQS0__oGSQS1___dT__ + 55
21 AppName 0x0001d224 _TPA__TTRXFo_iTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError___iT__XFo_oGSQS__oGSQS0__oGSQS1___dT__ + 100
22 AppName 0x0001e36e _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFdCb_dGSQS__dGSQS0__dGSQS1___dT__ + 142
23 CFNetwork 0x02c36158 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 181
24 Foundation 0x0092da35 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 12
25 Foundation 0x00854635 -[NSBlockOperation main] + 99
26 Foundation 0x00833a97 -[__NSOperationInternal _start:] + 700
27 Foundation 0x008337c9 -[NSOperation start] + 83
28 Foundation 0x00833613 __NSOQSchedule_f + 237
29 libdispatch.dylib 0x022ef3ff _dispatch_client_callout + 14
30 libdispatch.dylib 0x022d8578 _dispatch_queue_drain + 1424
31 libdispatch.dylib 0x022d7f90 _dispatch_queue_invoke + 142
32 libdispatch.dylib 0x022d9e06 _dispatch_root_queue_drain + 312
33 libdispatch.dylib 0x022dae67 _dispatch_worker_thread2 + 45
34 libsystem_pthread.dylib 0x0263fdab _pthread_wqthread + 336
35 libsystem_pthread.dylib 0x02643cce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks in advance!
It looks like your problem is that you are not on the mainThread, by the second line in the trace.
You are probably still running code in the background, due to the nature of HTTPRequest asynchronous handling of data... that's fine. You just need to get to the main thread, after all is said and done.
Here's how to probably fix it...
#IBAction func sendEcho(sender: AnyObject)
{
let callback = {(textString: String) in
dispatch_sync(dispatch_get_main_queue())
{
self.echoLog.text = textString //Yay!
}
}
HTTPRequest("http://localhost/echo", ["echo": "Echo!"], callback)
}
Reminder time UI updates should only be performed on the mainThread. Simply because doing so provides high priority for this thing to occur. Usually when you try to do UI updates on a background thread, you will see a delay between when the code is executed and when you see results. In this case, an Assertion failure (I like that). If you do not know if you are on the main thread, you can check it out by doing NSThread.isMainThread() which returns a bool.
Warning If you are already on the main thread while calling dispatch_sync(dispatch_get_main_queue()) {...} your app will freeze up, so make sure you know what thread you are on...
Apple will only let you modify UI components on the main event loop. It appears that the HTTPRequest is running callback on a background thread so you will have to explicitly run the change on the main thread:
let callback = { (textString: String) -> Void in
dispatch_async(dispatch_get_main_queue(), {
self.echoLog.text = textString
})
}

app crashes due to map kit with MKReverseGeocoder

I don't understand why this is crashing, whenever i came back to home page this app crashes, I have a file LocationSelectViewController.m when enabling zombie it throws an error
[LocationSelectViewController respondsToSelector:]: message sent to deallocated instance 0x27b96740
Let me share a crash log
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libobjc.A.dylib 0x3b2665d0 objc_msgSend + 16
1 MapKit 0x343b7492 -[MKReverseGeocoder _notifyResult:] + 70
2 ProtocolBuffer 0x389631b6 -[PBRequester connectionDidFinishLoading:] + 1042
3 Foundation 0x33eac912 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 + 14
4 Foundation 0x33dec764 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 196
5 Foundation 0x33dec680 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 56
6 CFNetwork 0x3324d64c ___delegate_didFinishLoading_block_invoke_0 + 24
7 CFNetwork 0x3324cd30 ___withDelegateAsync_block_invoke_0 + 52
8 CFNetwork 0x33275010 ___performAsync_block_invoke_068 + 16
9 CoreFoundation 0x334b6aca CFArrayApplyFunction + 174
10 CFNetwork 0x3327546e RunloopBlockContext::perform() + 70
11 CFNetwork 0x331d945e MultiplexerSource::perform() + 186
12 CoreFoundation 0x335458f4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
13 CoreFoundation 0x33545158 __CFRunLoopDoSources0 + 208
14 CoreFoundation 0x33543f2a __CFRunLoopRun + 642
15 CoreFoundation 0x334b7238 CFRunLoopRunSpecific + 352
16 CoreFoundation 0x334b70c4 CFRunLoopRunInMode + 100
17 GraphicsServices 0x37096336 GSEventRunModal + 70
18 UIKit 0x353d32b4 UIApplicationMain + 1116
19 PlanetTran 0x000af534 0xae000 + 5428
20 PlanetTran 0x000af4cc 0xae000 + 5324
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1 Crashed:
0 libsystem_kernel.dylib 0x3b74f5d0 kevent64 + 24
1 libdispatch.dylib 0x3b68ad22 _dispatch_mgr_invoke + 806
2 libdispatch.dylib 0x3b686374 _dispatch_mgr_thread + 32
Try to convert your application in ARC(Automatic reference counting).
message sent to deallocated instance means you are trying to send the message that object is destroyed Automatically so you are getting this exceptions.
For converting in ARC goto Xcode
Edit->Refactor->convert to objective c ARC

iOS: How to get stack trace of an unhandled std::exception?

If an unhandled NSException is thrown, the stack trace has a section like this:
Last Exception Backtrace:
0 CoreFoundation 0x32bd688f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x34b7b259 objc_exception_throw + 33
2 CoreFoundation 0x32bd65c5 -[NSException init] + 1
3 Foundation 0x37296bd7 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 263
...
But if std::exception is thrown, I get only this:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x34f2632c __pthread_kill + 8
1 libsystem_c.dylib 0x31e4c208 pthread_kill + 48
2 libsystem_c.dylib 0x31e45298 abort + 88
3 libc++abi.dylib 0x33bcaf64 abort_message + 40
4 libc++abi.dylib 0x33bc8346 default_terminate() + 18
5 libobjc.A.dylib 0x349f4368 _objc_terminate + 164
6 libc++abi.dylib 0x33bc83be safe_handler_caller(void (*)()) + 70
7 libc++abi.dylib 0x33bc844a std::terminate() + 14
8 libc++abi.dylib 0x33bc981e __cxa_rethrow + 82
9 libobjc.A.dylib 0x349f42a2 objc_exception_rethrow + 6
10 CoreFoundation 0x329a5506 CFRunLoopRunSpecific + 398
11 CoreFoundation 0x329a5366 CFRunLoopRunInMode + 98
12 GraphicsServices 0x32af2432 GSEventRunModal + 130
13 UIKit 0x34f84cce UIApplicationMain + 1074
14 APP_NAME 0x00086b10 main (main.m:68)
15 APP_NAME 0x00071b98 start + 32
How do I get the exact crash info from this crash log?
Update --
I've given HockeyApp a shot, but it has the same limitation as iTunes crash logs - it doesn't tell me the stack for an unhandled C++ exception.
What you're seeing is an unfortunate quirk of AppKit and UIKit. Both iOS and OS X have an exception handler in CFRunLoop that traps all uncaught exceptions. On OS X, the handler displays the exception to the user with a dialog box, but on iOS, the handler simply rethrows the exception.
Objective-C exceptions, as implemented by NSException, save their backtraces within the exception object right before the actual "throw" happens, as part of [NSException init] (or a similar initializer method). Unfortunately, C++ exceptions don't do the same. Normally, a C++ exception has a backtrace because the runtime library detects that there's no catch and immediately calls std::terminate, which in turn calls abort(), leaving the entire call stack intact, like so:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff93ef8d46 __kill + 10
1 libsystem_c.dylib 0x00007fff89968df0 abort + 177
2 libc++abi.dylib 0x00007fff8beb5a17 abort_message + 257
3 libc++abi.dylib 0x00007fff8beb33c6 default_terminate() + 28
4 libobjc.A.dylib 0x00007fff8a196887 _objc_terminate() + 111
5 libc++abi.dylib 0x00007fff8beb33f5 safe_handler_caller(void (*)()) + 8
6 libc++abi.dylib 0x00007fff8beb3450 std::terminate() + 16
7 libc++abi.dylib 0x00007fff8beb45b7 __cxa_throw + 111
8 test 0x0000000102999f3b main + 75
9 libdyld.dylib 0x00007fff8e4ab7e1 start + 1
However, when the run loop exception handler traps the exception, execution resumes normally within the catch block. The original backtrace is therefore lost. The rethrow subsequently calls std::terminate, but at this point, the call stack reflects the run loop exception handler.
To get a backtrace from a C++ exception in this circumstance, you have to throw an exception object which mimics NSException and reads the call stack as part of its constructor, and make sure that all exceptions thrown in your code do the same. std::exception doesn't do this, and it's not at all likely that any third-party code you're using will either.
File a bug with Apple asking them to remove the CFRunLoop exception handler, or at least provide an API for shutting it off. There is no API, not even an SPI, for doing this right now.
I've had luck with improving mpipe3's answer.
In my main method, I use a try-catch to get the C++ exception and then call a dispatch_sync on dispatch_get_global_queue. Now the full stack trace with line numbers will show on Crashlytics (crash manager).
int main(int argc, char *argv[]) {
#autoreleasepool {
#try{
return UIApplicationMain(argc, argv, nil, #"AppControllerClassName");
} #catch (NSException *exception) {/* Catch any uncaught exceptions and print out a friendly call stack. Instead of an ugly memory addresses. */
NSString * message = [NSString stringWithFormat:#"Uncaught exception %# : %#\n %#", exception.name, exception.reason, [exception callStackSymbols]];
[LogManager e:#"main.m" Message:message Exception: exception];
#throw;
} #catch (...){
//Attempt to get the correct stacktrace for C++ exceptions.
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
#throw;
});
}
return 0;
}
}
This works as it avoids the CFRunLoop exception handler by using GCD to throw the exception.
Following on from Gwynne Raskind answer you can avoid the CFRunLoop exception handler by using GCD to dispatch a call to a block of C++ code synchronously:
namespace
{
void MyThrowingCode()
{
throw std::runtime_error("My Exception");
}
}
- (void)objcHandlerCalledFromARunLoop
{
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
MyThrowingCode();
});
}
You might need to create your own queues rather than using a single shared queue.
The crash log looks like this:
0 libsystem_kernel.dylib 0x3aa39350 __pthread_kill + 8
1 libsystem_c.dylib 0x3a9affb2 pthread_kill + 54
2 libsystem_c.dylib 0x3a9ec366 abort + 90
3 libc++abi.dylib 0x39f94dda abort_message + 70
4 libc++abi.dylib 0x39f92094 default_terminate() + 20
5 libobjc.A.dylib 0x3a545a70 _objc_terminate() + 168
6 libc++abi.dylib 0x39f92118 safe_handler_caller(void (*)()) + 76
7 libc++abi.dylib 0x39f921b0 std::terminate() + 16
8 libc++abi.dylib 0x39f9359a __cxa_throw + 118
9 Test 0x000fddfc MyThrowingCode() (MainViewController.mm:177)
10 Test 0x000fe38c __35-[MainViewController toolsClick:]_block_invoke (MainViewController.mm:184)
11 libdispatch.dylib 0x3a95f5d8 _dispatch_client_callout + 20
12 libdispatch.dylib 0x3a962776 _dispatch_sync_f_invoke + 22
13 Test 0x000fde90 -[MainViewController toolsClick:] (MainViewController.mm:183)
14 UIKit 0x34744082 -[UIApplication sendAction:to:from:forEvent:] + 66
15 UIKit 0x3474410c -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 116
16 UIKit 0x34744082 -[UIApplication sendAction:to:from:forEvent:] + 66
17 UIKit 0x34744036 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
18 UIKit 0x34744010 -[UIControl sendAction:to:forEvent:] + 40
19 UIKit 0x347438c6 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 498
20 UIKit 0x34743db4 -[UIControl touchesEnded:withEvent:] + 484
21 UIKit 0x3466c5f4 -[UIWindow _sendTouchesForEvent:] + 520
22 UIKit 0x346598dc -[UIApplication sendEvent:] + 376
23 UIKit 0x346591ea _UIApplicationHandleEvent + 6194
24 GraphicsServices 0x363715f4 _PurpleEventCallback + 588
25 GraphicsServices 0x36371222 PurpleEventCallback + 30
26 CoreFoundation 0x3281f3e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
27 CoreFoundation 0x3281f386 __CFRunLoopDoSource1 + 134
28 CoreFoundation 0x3281e20a __CFRunLoopRun + 1378
29 CoreFoundation 0x32791238 CFRunLoopRunSpecific + 352
30 CoreFoundation 0x327910c4 CFRunLoopRunInMode + 100
31 GraphicsServices 0x36370336 GSEventRunModal + 70
32 UIKit 0x346ad2b4 UIApplicationMain + 1116
33 Test 0x00120462 main (main.mm:55)
34 libdyld.dylib 0x3a972b1c start + 0
looks like the exception is happening from inside UIApplicationMain()... You could try converting your main.m file to a main.mm file, and doing this:
int main(...)
{
try
{
return UIApplicationMain(...);
}
catch( exception e )
{
cerr < e.what() ;
}
}
I didn't actually try it, however...