Apps crashes 5 out of 10 when quiting

I have a small app that crashes 5 times out 10.

Any pointers were I have to look at?
The full crash report can be found in the Feedback case: <https://xojo.com/issue/50987>

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

Date/Time: 2018-01-03 13:25:52.137 +0100
OS Version: Mac OS X 10.13.2 (17C88)
Report Version: 12
Bridge OS Version: 3.0 (14Y661)
Anonymous UUID: A4FF4BB0-E235-4B78-028B-0BD067DCBCA0

Sleep/Wake UUID: A5F3C562-7C79-4A1A-AD27-1E6849F3C4C3

Time Awake Since Boot: 7200 seconds
Time Since Wake: 2100 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 00000001056b8000-000000010581c000 [ 1424K] r-x/rwx SM=COW /Applications/UpgradeTool.app/Contents/MacOS/UpgradeTool

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

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.xojo.XojoFramework 0x0000000105b65baf RuntimeObjectIsa + 76
1 com.xojo.XojoFramework 0x0000000105b77c00 RuntimeViewDestructor + 91
2 com.osbytes.UpgradeTool 0x00000001056c0dbb Window.__Exit%%o + 11
3 com.xojo.XojoFramework 0x0000000105b65a31 RuntimeUnlockObject + 815
4 com.xojo.XojoFramework 0x0000000105a71812 RuntimeView::UnifiedClose(bool) + 598
5 com.xojo.XojoFramework 0x00000001059fea79 0x105910000 + 977529
6 com.apple.AppKit 0x00007fff26d7d8dd __19-[NSWindow __close]_block_invoke + 185
7 com.apple.AppKit 0x00007fff26d7d817 -[NSWindow __close] + 297
8 com.apple.AppKit 0x00007fff2722275a -[NSApplication(NSResponder) sendAction:to:from:] + 312
9 com.apple.AppKit 0x00007fff26cc8933 -[NSControl sendAction:to:] + 86
10 com.apple.AppKit 0x00007fff26cc885b __26-[NSCell _sendActionFrom:]_block_invoke + 136
11 com.apple.AppKit 0x00007fff26cc8761 -[NSCell _sendActionFrom:] + 183
12 com.apple.AppKit 0x00007fff26d09a18 -[NSButtonCell _sendActionFrom:] + 97
13 com.apple.AppKit 0x00007fff26cc6fca -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438
14 com.apple.AppKit 0x00007fff26d0975f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777
15 com.apple.AppKit 0x00007fff26cc5a64 -[NSControl mouseDown:] + 965
16 com.apple.AppKit 0x00007fff26d5ff1d -[_NSThemeWidget mouseDown:] + 86
17 com.apple.AppKit 0x00007fff273c1959 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
18 com.apple.AppKit 0x00007fff273be5b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
19 com.apple.AppKit 0x00007fff273bd85c -[NSWindow(NSEventRouting) sendEvent:] + 497
20 com.xojo.XojoFramework 0x00000001059f357c 0x105910000 + 931196
21 com.apple.AppKit 0x00007fff2721e617 -[NSApplication(NSEvent) sendEvent:] + 307
22 com.xojo.XojoFramework 0x00000001059e2f9d 0x105910000 + 864157
23 com.osbytes.UpgradeTool 0x00000001056f4075 Application._CallFunctionWithExceptionHandling%%op + 181
24 com.xojo.XojoFramework 0x0000000105b634df CallFunctionWithExceptionHandling(void (*)()) + 262
25 com.xojo.XojoFramework 0x00000001059e2f18 0x105910000 + 864024
26 com.apple.AppKit 0x00007fff26a7fd9d -[NSApplication run] + 812
27 com.xojo.XojoFramework 0x0000000105b6180b RuntimeRun + 40
28 com.osbytes.UpgradeTool 0x0000000105775523 REALbasic._RuntimeRun + 19
29 com.osbytes.UpgradeTool 0x00000001057ff8de _Main + 478
30 com.osbytes.UpgradeTool 0x00000001057ff163 main + 19
31 libdyld.dylib 0x00007fff50cfc115 start + 1

Thread 1:
0 libsystem_kernel.dylib 0x00007fff50e4c562 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff50f8706a _pthread_wqthread + 1035
2 libsystem_pthread.dylib 0x00007fff50f86c4d start_wqthread + 13

Thread 2:
0 libsystem_kernel.dylib 0x00007fff50e4c562 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff50f8726f _pthread_wqthread + 1552
2 libsystem_pthread.dylib 0x00007fff50f86c4d start_wqthread + 13

Thread 3:
0 libsystem_kernel.dylib 0x00007fff50e4c562 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff50f8726f _pthread_wqthread + 1552
2 libsystem_pthread.dylib 0x00007fff50f86c4d start_wqthread + 13

Thread 4:
0 libsystem_kernel.dylib 0x00007fff50e4c562 __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x00007fff50f8726f _pthread_wqthread + 1552
2 libsystem_pthread.dylib 0x00007fff50f86c4d start_wqthread + 13

0 com.xojo.XojoFramework 0x0000000105b65baf RuntimeObjectIsa + 76

You have some code to show that’s doing Object IsA … ?
It’s crashing probably there, i guess the object is Nil or something (based from this: RuntimeViewDestructor).

Is there a MouseDown event somewhere that calls Window.Close or otherwise causes the window to destruct (such as calling ‘quit’)

If so, try moving such code to a different location, such as MouseUp, or into a single-fire timer which fires immediately.

Alternatively is there anything potentially problematic such as re-instantiating the window in a destructor or close / cancelclose event?

Sorry, I have no such code in this app.

[quote=367234:@Thomas Sanham]Is there a MouseDown event somewhere that calls Window.Close or otherwise causes the window to destruct (such as calling ‘quit’)

If so, try moving such code to a different location, such as MouseUp, or into a single-fire timer which fires immediately.[/quote]

The app only has one window and one sheetwindow. The sheet window has a button with in the button Action event ‘sheet window.close’.
But the crash happens when I quit the app, even when the sheet window isn’t shown.

I compiled it with Xojo 2016R2 and it doesn’t crash. Seems to be a bug in Xojo 2017R2.1

Looks like a problem with MouseDown:

13 com.apple.AppKit 0x00007fff26cc6fca -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438 14 com.apple.AppKit 0x00007fff26d0975f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777 15 com.apple.AppKit 0x00007fff26cc5a64 -[NSControl mouseDown:] + 965 16 com.apple.AppKit 0x00007fff26d5ff1d -[_NSThemeWidget mouseDown:] + 86 17 com.apple.AppKit 0x00007fff273c1959 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891

The odd part is that there are no MouseDown events in my app.

FWIW, my app was experiencing exactly the same crash log signatures and I tracked it to this line of code:

textarea1.StyledText.RTFData = s

Where s was a string of RTFData saved in a file, and then read back in. Commented out that line and the app no longer crashed. Might be worth taking a look if you are doing something similar.

[quote=367252:@Richard Nicolella]FWIW, my app was experiencing exactly the same crash log signatures and I tracked it to this line of code:

textarea1.StyledText.RTFData = s

Where s was a string of RTFData saved in a file, and then read back in. Commented out that line and the app no longer crashed. Might be worth taking a look if you are doing something similar.[/quote]

In fact, I am using a textarea, and do load and save the content. The textarea has Styled text enabled. But I do not use .RTFData

Any declares?

No declares either. :slight_smile:

Is there an Exception command after the Quit command? This sometimes tripped up my quitting methods causing an error on shutdown.

No exception are used at all.

In the meantime I stripped the app completely and still not sure were it goes wrong. But I am pretty sure it is the TextArea control. When I disable them, the crashes are gone.
It’s still odd it happens at random. I’m really trying to find a way so it can be triggered every time.

BTW it is for sure an issue with the latest Xojo builds. Xojo 2016R2 does not trigger this.

Any code in App.Close or Window.close ?

Only a window.close in the sheetwindow.

Try putting that window.close call in a single timer with a period of 1ms rather than calling it directly.

I want to thank everyone for all the suggestions!
Sadly this is an odd duck and I cannot pinpoint the problem. I tried with all my Xojo knowledge and tricks to find why this happens. I give up. The app is for internal use only so I can live with it - it only happens on quitting the app.

If a Xojo dev needs more info, let me know in the feedback case.

I now am 100% sure the culprit is the TextArea control. When I remove those controls, no crashing is happening.
The odd bit is that the TextArea control in this simple apps isn’t doing anything thing. I just read the content to a String variable. But that code isn’t even launch and still the app crashes.

I will try to make an example that triggers this.

BTW compiling it to Windows, does not crash the app.