MacOS 64 bit crash after application exit

We’re seeing a crash immediately after exit on Mac High Sierra when running a 64 bit app. This crash occurs after a user closes the main window, not after calling Quit(). I tried setting AutoQuit=True after reading a similar post here on the forums but it did not help. There are no threads in the app. There is a Shell instance the app uses but the Shell.Close() function is called before the window is closed. Crash report below.

Process: *** [42029]
Path: ***
Identifier: com.whitesky.mactest01
Version: ??? (1.0.0.0.0)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Privacy Scanner [42029]
User ID: 501

Date/Time: 2018-01-11 18:15:13.138 -0800
OS Version: Mac OS X 10.13.1 (17B1003)
Report Version: 12
Anonymous UUID: 8DCD856C-9C21-51F6-B0B7-A730B14C3398

Sleep/Wake UUID: F51D9A8F-1912-4889-861D-7D7688417849

Time Awake Since Boot: 2400000 seconds
Time Since Wake: 29000 seconds

System Integrity Protection: disabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000100004263
Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]

VM Regions Near 0x100004263:
–>
__TEXT 0000000109f28000-000000010a0f2000 [ 1832K] r-x/rwx SM=COW n [**]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.xojo.XojoFramework 0x000000010a43ebaf RuntimeObjectIsa + 76
1 com.xojo.XojoFramework 0x000000010a450c00 RuntimeViewDestructor + 91
2 com.whitesky.mactest01 0x0000000109f39b3b Window.__Exit%%o + 11
3 com.xojo.XojoFramework 0x000000010a43ea31 RuntimeUnlockObject + 815
4 com.xojo.XojoFramework 0x000000010a34a812 RuntimeView::UnifiedClose(bool) + 598
5 com.xojo.XojoFramework 0x000000010a2d7a79 0x10a1e9000 + 977529
6 com.apple.AppKit 0x00007fff3039e667 __19-[NSWindow __close]_block_invoke + 185
7 com.apple.AppKit 0x00007fff3039e5a1 -[NSWindow __close] + 297
8 com.apple.AppKit 0x00007fff30842a7a -[NSApplication(NSResponder) sendAction:to:from:] + 312
9 com.apple.AppKit 0x00007fff302e9777 -[NSControl sendAction:to:] + 86
10 com.apple.AppKit 0x00007fff302e969f __26-[NSCell _sendActionFrom:]_block_invoke + 136
11 com.apple.AppKit 0x00007fff302e95a5 -[NSCell _sendActionFrom:] + 183
12 com.apple.AppKit 0x00007fff3032a858 -[NSButtonCell _sendActionFrom:] + 97
13 com.apple.AppKit 0x00007fff302e7e06 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438
14 com.apple.AppKit 0x00007fff3032a59f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777
15 com.apple.AppKit 0x00007fff302e68a4 -[NSControl mouseDown:] + 965
16 com.apple.AppKit 0x00007fff30380ced -[_NSThemeWidget mouseDown:] + 86
17 com.apple.AppKit 0x00007fff309e1a01 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
18 com.apple.AppKit 0x00007fff309de658 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
19 com.apple.AppKit 0x00007fff309dd904 -[NSWindow(NSEventRouting) sendEvent:] + 497
20 com.xojo.XojoFramework 0x000000010a2cc57c 0x10a1e9000 + 931196
21 com.apple.AppKit 0x00007fff3083e937 -[NSApplication(NSEvent) sendEvent:] + 307
22 com.xojo.XojoFramework 0x000000010a2bbf9d 0x10a1e9000 + 864157
23 com.whitesky.mactest01 0x0000000109f79ee5 Application._CallFunctionWithExceptionHandling%%op + 181
24 com.xojo.XojoFramework 0x000000010a43c4df CallFunctionWithExceptionHandling(void (*)()) + 262
25 com.xojo.XojoFramework 0x000000010a2bbf18 0x10a1e9000 + 864024
26 com.apple.AppKit 0x00007fff300a0861 -[NSApplication run] + 812
27 com.xojo.XojoFramework 0x000000010a43a80b RuntimeRun + 40
28 com.whitesky.mactest01 0x0000000109ffd603 REALbasic._RuntimeRun + 19
29 com.whitesky.mactest01 0x000000010a0d1e28 _Main + 536
30 com.whitesky.mactest01 0x000000010a0d0c73 main + 19
31 libdyld.dylib 0x00007fff5a071145 start + 1

We tried removing the shell instance and some HTTPSocket calls to see if it resolved the issue. It did not. What else could cause this kind of crash on a 64 bit build? The crash does not occur on a 32 bit build.

Using any declares???

No Declares in the app. Anything else we should check for?

Look at the report, I’d suggest the crash is caused by it doing something with something that doesn’t exist.

There’s quite a few people on here who’re having the same problem.

I think it may because Xojo winds down the application, goes through and calls all the destructors and such, where as Apple seem to prefer chopping the head off and flushing it out of memory.

Try putting this in your “CancelClose” event, make sure that you’ve saved all the user before you do so.

[code]Function CancelClose() Handles CancelClose as Boolean
/// — Make sure that all the user data and preferences are saved.

#if targetMacOS then
declare function NSClassFromString lib “Cocoa” ( aClassName as CFStringRef ) as integer
declare function sharedApplication lib “Cocoa” selector “sharedApplication” ( classRef as integer ) as integer
declare sub terminate lib “Cocoa” selector “terminate:” ( appRef as integer, sender as integer )

Dim appInstance as integer = sharedApplication( NSClassFromString( "NSApplication" ) )
terminate( appInstance, appInstance )

#endif
End Function[/code]

I’ve not tested it on High Sierra as I’ve not upgraded our production machines yet, and currently have no plans to do so either.

I have this with several apps (even very simple projects).
I have put a lot (and really) a lot of time finding why this happens. Sadly never found why.
It is also random and not always happens. IMO it has something to do how Xojo compiled apps handles cleaning up when quitting an app.

It never got solved and learned to leave with it.

Thanks Sam. That workaround did the trick.

Hey Sam! Thanks for this code. It does resolve the crashing I have.

Now, shouldn’t Xojo Inc take a look at this? This crashing is bugging me for a long time ever sends macOS10.13 was released.
Can you also explain what exactly your code is doing? Is it ‘terminating’ the app like some sort of Force Quit?

Well, hilarious. I was updating a feedback report of this crashing issues. I quitted the Feedback app and guess what … it crashes. :slight_smile:
I can recommend using Sams code to avoid this :wink:

Process: Feedback [2412]
Path: /Applications/Feedback.app/Contents/MacOS/Feedback
Identifier: com.xojo.feedback
Version: 2017r1.2 (17.1.2.3.278)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Feedback [2412]
User ID: 501

Date/Time: 2018-01-12 22:33:07.995 +0100
OS Version: Mac OS X 10.13.2 (17C205)
Report Version: 12
Bridge OS Version: 3.0 (14Y661)
Anonymous UUID: A4FF4BB0-E235-4B78-028B-0BD067DCBCA0

Sleep/Wake UUID: 4DB26D6C-5538-4CB3-89DE-7A66ED6F4CFA

Time Awake Since Boot: 17000 seconds
Time Since Wake: 1800 seconds

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000428
Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]

VM Regions Near 0x428:
–>
__TEXT 0000000108dfe000-0000000109fb7000 [ 17.7M] r-x/rwx SM=COW /Applications/Feedback.app/Contents/MacOS/Feedback

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.xojo.XojoFramework 0x000000010a55bd89 listColumnGetter + 122
1 com.xojo.feedback 0x0000000108eb4570 Listbox.Column%o%oi8 + 96
2 com.xojo.feedback 0x00000001091e3262 ReportListView.ReportListView.PositionFilterBar%%o<ReportListView.ReportListView> + 2738
3 com.xojo.feedback 0x00000001091c3ebf ReportListView.ReportListView.Timer1_Action%%o<ReportListView.ReportListView>o + 591
4 com.xojo.feedback 0x0000000108fff43b Delegate.IM_Invoke%%o + 43
5 com.xojo.feedback 0x0000000108fff485 AddHandler.Stub.0%% + 21
6 com.xojo.XojoFramework 0x000000010a5670bb 0x10a3bc000 + 1749179
7 com.apple.CoreFoundation 0x00007fff2fd9dbb4 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20
8 com.apple.CoreFoundation 0x00007fff2fd9d827 __CFRunLoopDoTimer + 1095
9 com.apple.CoreFoundation 0x00007fff2fd9d32a __CFRunLoopDoTimers + 346
10 com.apple.CoreFoundation 0x00007fff2fd9492b __CFRunLoopRun + 2427
11 com.apple.CoreFoundation 0x00007fff2fd93d23 CFRunLoopRunSpecific + 483
12 com.apple.HIToolbox 0x00007fff2f0abe26 RunCurrentEventLoopInMode + 286
13 com.apple.HIToolbox 0x00007fff2f0aba9f ReceiveNextEventCommon + 366
14 com.apple.HIToolbox 0x00007fff2f0ab914 _BlockUntilNextEventMatchingListInModeWithFilter + 64
15 com.apple.AppKit 0x00007fff2d376f5f _DPSNextEvent + 2085
16 com.apple.AppKit 0x00007fff2db0cb4c -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
17 com.xojo.XojoFramework 0x000000010a3faa5a 0x10a3bc000 + 256602
18 com.xojo.XojoFramework 0x000000010a3faa9e 0x10a3bc000 + 256670
19 com.xojo.feedback 0x0000000108fdc217 Delegate.Invoke%% + 7
20 com.xojo.feedback 0x0000000108e96ad1 Application._CallFunctionWithExceptionHandling%%op + 273
21 com.xojo.XojoFramework 0x000000010a55f4e5 0x10a3bc000 + 1717477
22 com.xojo.XojoFramework 0x000000010a3fa9f7 0x10a3bc000 + 256503
23 com.apple.AppKit 0x00007fff2d5589cf -[NSApplication _shouldTerminate] + 1367
24 com.apple.AppKit 0x00007fff2d557ec5 -[NSApplication terminate:] + 818
25 com.xojo.XojoFramework 0x000000010a55d942 RuntimeRun + 207
26 com.xojo.feedback 0x0000000108f876a8 REALbasic._RuntimeRun + 24
27 com.xojo.feedback 0x0000000109e5a00a _Main + 538
28 com.xojo.feedback 0x0000000109e54b51 main + 65
29 com.xojo.feedback 0x0000000108dff7d4 start + 52

Thread 1:: Dispatch queue: NSCGSDisableUpdates
0 libsystem_kernel.dylib 0x00007fff577dd7c2 mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff577dccdc mach_msg + 60
2 com.apple.SkyLight 0x00007fff516ba285 CGSUpdateManager::enable_updates_common() + 565
3 com.apple.SkyLight 0x00007fff5165eb44 CGSUpdateManager::enable_update(unsigned long long) + 320
4 libdispatch.dylib 0x00007fff57665591 _dispatch_call_block_and_release + 12
5 libdispatch.dylib 0x00007fff5765dd50 _dispatch_client_callout + 8
6 libdispatch.dylib 0x00007fff5767220c _dispatch_queue_serial_drain + 635
7 libdispatch.dylib 0x00007fff576650fd _dispatch_queue_invoke + 373
8 libdispatch.dylib 0x00007fff57672f02 _dispatch_root_queue_drain_deferred_wlh + 332
9 libdispatch.dylib 0x00007fff57676d16 _dispatch_workloop_worker_thread + 880
10 libsystem_pthread.dylib 0x00007fff57922033 _pthread_wqthread + 980
11 libsystem_pthread.dylib 0x00007fff57921c4d start_wqthread + 13

Thread 2:
0 libsystem_kernel.dylib 0x00007fff577e7562 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff5792226f _pthread_wqthread + 1552
2 libsystem_pthread.dylib 0x00007fff57921c4d start_wqthread + 13

You’re welcome, I’m glad to hear that it works and helped, like I stressed before, make sure that everything is saved BEFORE you call this, you won’t get another chance to save the data!

I am pleased to hear that, don’t forget to make sure that everything is saved before you call this function. Listen, I am sorry for not thinking of this earlier when we were trying to figure what was making your apps crash last year. I don’t know why, but when I saw it this time, I had that thought.

I found this when I was trying to support window restoration, in that none of the window data was saved when a Xojo application was allowed to shut down correctly. The window data was being saved while the application was running, so I came to the assumption that Xojo was being a nice guy and winding everything down (problem to ensure all CancelClose events fire and destructors), but because it was winding down the windows, window restoration wouldn’t work. So I looked into other options and this is what I found.

I don’t think it’s like Force Quit.

Also don’t forget that one of Apple’s memory management ‘techniques’ is that it can terminate applications to free up memory and then when the user needs that application, it relaunches it (and through the power of window restoration) it seems like it was running all the time.

Here’s what Apple says about the terminate function.

Do not bother to put final cleanup code in your app’s main() function—it will never be executed. If cleanup is necessary, perform that cleanup in the delegate’s applicationWillTerminate: method.

The crash in Feedback is a different one:

0 com.xojo.XojoFramework 0x000000010a55bd89 listColumnGetter + 122 1 com.xojo.feedback 0x0000000108eb4570 Listbox.Column%o<ListColumn>%o<Listbox>i8 + 96 2 com.xojo.feedback 0x00000001091e3262 ReportListView.ReportListView.PositionFilterBar%%o<ReportListView.ReportListView> + 2738 3 com.xojo.feedback 0x00000001091c3ebf ReportListView.ReportListView.Timer1_Action%%o<ReportListView.ReportListView>o<Timer> + 591 4 com.xojo.feedback 0x0000000108fff43b Delegate.IM_Invoke%%o<Timer> + 43 5 com.xojo.feedback 0x0000000108fff485 AddHandler.Stub.0%% + 21

Original crash:

0 com.xojo.XojoFramework 0x000000010a43ebaf RuntimeObjectIsa + 76 1 com.xojo.XojoFramework 0x000000010a450c00 RuntimeViewDestructor + 91 2 com.whitesky.mactest01 0x0000000109f39b3b Window.__Exit%%o<Window> + 11 3 com.xojo.XojoFramework 0x000000010a43ea31 RuntimeUnlockObject + 815 4 com.xojo.XojoFramework 0x000000010a34a812 RuntimeView::UnifiedClose(bool) + 598 5 com.xojo.XojoFramework 0x000000010a2d7a79 0x10a1e9000 + 977529

But I’ll try Sam’s code for a different problem that I have. With 64bit the debug app won’t quit. Seems to only my own problem though. See <https://xojo.com/issue/48395> .

Yes, it is different. But I can show several other crashes when quitting an Xojo compiled app running in macOS 10.13
Although most cash are related to “RuntimeObjectIsa”.
I even have a simple app that has 1 window, 1 sheet window, 2 Textarea and 2 Textfields controls.
Further it uses an array, .Some code from MBS to send a mail. And nothing more. It crashes at random when compiling to 64bit. Yet, it does not crash when compiled to 32bit.
An important note is that the 64bit apps do not crash on older macOS versions.

Maybe Apple changed some thing related to quitting an app, I don’t know. But it for sure happening on several projects I have.

Sam’s solution is ok for me know. Still, Xojo Inc really should take this serious imo.

Below my last crash of the app I described above (read: very simple app).

Process: UpgradeTool [1850]
Path: /Applications/UpgradeTool.app/Contents/MacOS/UpgradeTool
Identifier: com.osbytes.UpgradeTool
Version: 1.1.0 (1.1.0.3.0)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: UpgradeTool [1850]
User ID: 501

Date/Time: 2018-01-12 20:39:41.676 +0100
OS Version: Mac OS X 10.13.2 (17C205)
Report Version: 12
Bridge OS Version: 3.0 (14Y661)
Anonymous UUID: A4FF4BB0-E235-4B78-028B-0BD067DCBCA0

Sleep/Wake UUID: 22976FAE-31AC-4581-8529-1FC409BF7756

Time Awake Since Boot: 15000 seconds
Time Since Wake: 400 seconds

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008
Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]

VM Regions Near 0x8:

__TEXT 000000010c341000-000000010c4aa000 [ 1444K] r-x/rwx SM=COW /Applications/UpgradeTool.app/Contents/MacOS/UpgradeTool

Application Specific Information:
Calling windowShouldClose: on the delegate for the XOJWindow 0x7fa88a615250

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.xojo.XojoFramework 0x000000010c7f5baf RuntimeObjectIsa + 76
1 com.xojo.XojoFramework 0x000000010c807c00 RuntimeViewDestructor + 91
2 com.osbytes.UpgradeTool 0x000000010c3495eb Window.__Exit%%o + 11
3 com.xojo.XojoFramework 0x000000010c7f5a31 RuntimeUnlockObject + 815
4 com.xojo.XojoFramework 0x000000010c701812 RuntimeView::UnifiedClose(bool) + 598
5 com.xojo.XojoFramework 0x000000010c68ea79 0x10c5a0000 + 977529
6 com.apple.AppKit 0x00007fff2d6698dd __19-[NSWindow __close]_block_invoke + 185
7 com.apple.AppKit 0x00007fff2d669817 -[NSWindow __close] + 297
8 com.apple.AppKit 0x00007fff2db0e75a -[NSApplication(NSResponder) sendAction:to:from:] + 312
9 com.apple.AppKit 0x00007fff2d5b4933 -[NSControl sendAction:to:] + 86
10 com.apple.AppKit 0x00007fff2d5b485b __26-[NSCell _sendActionFrom:]_block_invoke + 136
11 com.apple.AppKit 0x00007fff2d5b4761 -[NSCell _sendActionFrom:] + 183
12 com.apple.AppKit 0x00007fff2d5f5a18 -[NSButtonCell _sendActionFrom:] + 97
13 com.apple.AppKit 0x00007fff2d5b2fca -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438
14 com.apple.AppKit 0x00007fff2d5f575f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777
15 com.apple.AppKit 0x00007fff2d5b1a64 -[NSControl mouseDown:] + 965
16 com.apple.AppKit 0x00007fff2d64bf1d -[_NSThemeWidget mouseDown:] + 86
17 com.apple.AppKit 0x00007fff2dcad959 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
18 com.apple.AppKit 0x00007fff2dcaa5b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
19 com.apple.AppKit 0x00007fff2dca985c -[NSWindow(NSEventRouting) sendEvent:] + 497
20 com.xojo.XojoFramework 0x000000010c68357c 0x10c5a0000 + 931196
21 com.apple.AppKit 0x00007fff2db0a617 -[NSApplication(NSEvent) sendEvent:] + 307
22 com.xojo.XojoFramework 0x000000010c672f9d 0x10c5a0000 + 864157
23 com.osbytes.UpgradeTool 0x000000010c37c8a5 Application._CallFunctionWithExceptionHandling%%op + 181
24 com.xojo.XojoFramework 0x000000010c7f34df CallFunctionWithExceptionHandling(void (*)()) + 262
25 com.xojo.XojoFramework 0x000000010c672f18 0x10c5a0000 + 864024
26 com.apple.AppKit 0x00007fff2d36bd9d -[NSApplication run] + 812
27 com.xojo.XojoFramework 0x000000010c7f180b RuntimeRun + 40
28 com.osbytes.UpgradeTool 0x000000010c3fdd53 REALbasic._RuntimeRun + 19
29 com.osbytes.UpgradeTool 0x000000010c48d10e _Main + 478
30 com.osbytes.UpgradeTool 0x000000010c48c993 main + 19
31 libdyld.dylib 0x00007fff57697115 start + 1

Yeah, Sam’s code works. I had to try some locations but I can finally do a debug on 64bit without getting annoyed.