Apple Silicon: ShowModal crash

I have a rather old CRM project that I have been updating since 2006. In this project I call a SearchCustomer Window with which I can search a customer in my database and send that info back to the main window from which it’s called. I do that by using a ShowModal in the SearchCustomer window that keeps the app waiting until it receives a customer back from SearchCustomer. This has worked for over 15 years up until now: our new Apple Silicon machines with Monterey keep throwing errors when you open the search window and before choosing a customer you switch back and forth to/from another application. If I don’t switch, just search a customer and select it and continue working in my app, the app resumes without error (so luckily the crash only happens occasionly).

I went through the code with a fine toothcomb and can only solve the error problem if I replace ShowModal with Show, but then the app doesn’t work properly anymore since the code keeps running without waiting for the search result.

Since I fear it’s a bug I can’t solve, because there’s nothing wrong with the code (it runs fine on Intel machines): is there another way to keep the app waiting for info like a ShowModal command does?

BTW: I use Xojo 2021 release 3.1

My crash log:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Comos [11040]
Path:                  /Applications/Comos/Comos.app/Contents/MacOS/Comos
Identifier:            com.Comatherm.Comos
Version:                (6.1.0.3.86)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               502

Date/Time:             2022-02-03 09:29:23.2866 +0100
OS Version:            macOS 12.1 (21C52)
Report Version:        12
Anonymous UUID:        74BBD9E1-1B83-F80B-A3F0-888F52446A88

Sleep/Wake UUID:       DCA696E9-FCD9-49F5-BE91-1E4A1E897CE6

Time Awake Since Boot: 42000 seconds
Time Since Wake:       3740 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 0x0000000000000000
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

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

VM Region Info: 0 is not in any region.  Bytes before following region: 4305715200
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      100a40000-101c74000    [ 18.2M] r-x/r-x SM=COW  ...s/MacOS/Comos

Application Specific Information:
Performing @selector(performClick:) from sender XOJButton 0x10e912370


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_platform.dylib      	       0x18dfbd884 _platform_strlen + 4
1   libsystem_c.dylib             	       0x18de70548 __vfprintf + 4576
2   libsystem_c.dylib             	       0x18de6f1e4 __v2printf + 408
3   libsystem_c.dylib             	       0x18de9e150 _vasprintf + 224
4   HIToolbox                     	       0x196e3956c HILogToClient + 44
5   HIToolbox                     	       0x196e39988 HIPrintBacktrace + 44
6   HIToolbox                     	       0x196c7a440 MenuBarInstance::EnsureAutoShowObserver() + 120
7   HIToolbox                     	       0x196c1c144 SetMenuBarObscured + 220
8   HIToolbox                     	       0x196c1bdb4 HIApplication::HandleActivated(OpaqueEventRef*, unsigned char, OpaqueWindowPtr*, unsigned char) + 172
9   HIToolbox                     	       0x196c15e68 HIApplication::EventObserver(unsigned int, OpaqueEventRef*, void*) + 296
10  HIToolbox                     	       0x196bdcc0c _NotifyEventLoopObservers + 172
11  HIToolbox                     	       0x196c1585c AcquireEventFromQueue + 508
12  HIToolbox                     	       0x196c04c2c ReceiveNextEventCommon + 376
13  HIToolbox                     	       0x196c04a9c _BlockUntilNextEventMatchingListInModeWithFilter + 72
14  AppKit                        	       0x190bc8ce0 _DPSNextEvent + 844
15  AppKit                        	       0x190bc7584 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1332
16  XojoFramework                 	       0x102e6ade4 0x102ddc000 + 585188
17  AppKit                        	       0x190e7af7c -[NSApplication _doModalLoop:peek:] + 308
18  AppKit                        	       0x190ff11c4 __33-[NSApplication runModalSession:]_block_invoke_2 + 96
19  AppKit                        	       0x190ff1148 __33-[NSApplication runModalSession:]_block_invoke + 116
20  AppKit                        	       0x190e79198 _NSTryRunModal + 128
21  AppKit                        	       0x190ff1004 -[NSApplication runModalSession:] + 148
22  XojoFramework                 	       0x102fec030 ModalEvents(unsigned char) + 76
23  XojoFramework                 	       0x103000e74 RuntimeShowModalWithinWindow + 356
24  Comos                         	       0x100aa27bc Window.ShowModal%%o<Window> + 44
25  Comos                         	       0x10186ca9c ZoekOfferte.ZoekOfferte.ZoekenOff%s%o<ZoekOfferte.ZoekOfferte>bs + 396
26  Comos                         	       0x100e2e484 Offertescherm.Offertescherm.ButZoekOfferte_Action%%o<Offertescherm.Offertescherm>o<PushButton> + 828
27  Comos                         	       0x10104cc4c Delegate.IM_Invoke%%o<PushButton> + 60
28  Comos                         	       0x10104c610 AddHandler.Stub.15%% + 56
29  AppKit                        	       0x190dcd0c0 -[NSApplication(NSResponder) sendAction:to:from:] + 456
30  AppKit                        	       0x190dccec0 -[NSControl sendAction:to:] + 96
31  AppKit                        	       0x190dccdc8 __26-[NSCell _sendActionFrom:]_block_invoke + 152
32  AppKit                        	       0x190dcccbc -[NSCell _sendActionFrom:] + 196
33  AppKit                        	       0x190dccbe8 -[NSButtonCell _sendActionFrom:] + 104
34  AppKit                        	       0x190dc9a28 NSControlTrackMouse + 1720
35  AppKit                        	       0x190dc9344 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 160
36  AppKit                        	       0x190dc91b8 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 740
37  AppKit                        	       0x190dc8420 -[NSControl mouseDown:] + 636
38  XojoFramework                 	       0x102e6efcc 0x102ddc000 + 602060
39  AppKit                        	       0x190dc6874 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4524
40  AppKit                        	       0x190d39ce4 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2444
41  AppKit                        	       0x190d390ec -[NSWindow(NSEventRouting) sendEvent:] + 348
42  XojoFramework                 	       0x102e7ba60 0x102ddc000 + 653920
43  AppKit                        	       0x190d38050 -[NSApplication(NSEvent) sendEvent:] + 2776
44  XojoFramework                 	       0x102e6ad48 0x102ddc000 + 585032
45  Comos                         	       0x100ad1c54 Application._CallFunctionWithExceptionHandling%%o<Application>p + 164
46  XojoFramework                 	       0x102febf54 CallFunctionWithExceptionHandling(void (*)()) + 180
47  XojoFramework                 	       0x102e6acf8 0x102ddc000 + 584952
48  AppKit                        	       0x190ff059c -[NSApplication _handleEvent:] + 76
49  AppKit                        	       0x190bb95cc -[NSApplication run] + 636
50  XojoFramework                 	       0x102fea7bc RuntimeRun + 48
51  Comos                         	       0x100b91df4 REALbasic._RuntimeRun + 28
52  Comos                         	       0x101b0d7b8 _Main + 528
53  Comos                         	       0x101b08440 main + 36
54  dyld                          	       0x1023410f4 start + 520

Thread 1:: com.apple.NSEventThread
0   libsystem_kernel.dylib        	       0x18df6d954 mach_msg_trap + 8
1   libsystem_kernel.dylib        	       0x18df6dd00 mach_msg + 76
2   CoreFoundation                	       0x18e074ed8 __CFRunLoopServiceMachPort + 372
3   CoreFoundation                	       0x18e073390 __CFRunLoopRun + 1212
4   CoreFoundation                	       0x18e072734 CFRunLoopRunSpecific + 600
5   AppKit                        	       0x190d35c90 _NSEventThread + 196
6   libsystem_pthread.dylib       	       0x18dfa9240 _pthread_start + 148
7   libsystem_pthread.dylib       	       0x18dfa4024 thread_start + 8

Thread 2:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 4:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 5:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 6:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 7:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 8:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 9:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0

Thread 10:
0   libsystem_pthread.dylib       	       0x18dfa4010 start_wqthread + 0


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000001   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x000000012680a584
    x4: 0x0000000000002800   x5: 0x0000000000000020   x6: 0x0000000000000025   x7: 0x0000000000000000
    x8: 0x0000000000000001   x9: 0x000000018deebe77  x10: 0x0000000000000001  x11: 0x0000000000000000
   x12: 0x0000000000000048  x13: 0x00000000e8820825  x14: 0x0000000000000010  x15: 0x0000000000021000
   x16: 0x000000018dfbd880  x17: 0x00000001e8781fe0  x18: 0x0000000158193940  x19: 0x000000016f3bd050
   x20: 0x0000000000000001  x21: 0x000000012680cdf0  x22: 0x000000000000006b  x23: 0x0000000000000073
   x24: 0x000000000000000a  x25: 0x000000016f3bd168  x26: 0x000000016f3bd160  x27: 0x0000000000000000
   x28: 0x000000012680cdf2   fp: 0x000000016f3bd420   lr: 0x000000018de70548
    sp: 0x000000016f3bd050   pc: 0x000000018dfbd884 cpsr: 0x20001000
   far: 0x0000000000000000  esr: 0x92000006 (Data Abort) byte read Translation fault

Binary Images:
       0x18dfbc000 -        0x18dfc3fff libsystem_platform.dylib (*) <ef6555f4-7a8e-3e51-9b40-5381482dee4d> /usr/lib/system/libsystem_platform.dylib
       0x18de6d000 -        0x18deedfff libsystem_c.dylib (*) <00fc01c7-36bc-3193-86a3-5c03046b45fb> /usr/lib/system/libsystem_c.dylib
       0x196bd2000 -        0x196f01fff com.apple.HIToolbox (2.1.1) <01b981b8-a2d8-374d-9a0e-c4ac8c1009da> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox
       0x190b87000 -        0x191a3afff com.apple.AppKit (6.9) <a8bbc643-113d-310f-96b6-77a973bf2dba> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
       0x102ddc000 -        0x1030fffff com.xojo.XojoFramework (1.0) <4a5f8de8-eefe-37a6-ba0d-bf7cb4ecd1fb> /Applications/Comos/Comos.app/Contents/Frameworks/XojoFramework.framework/Versions/A/XojoFramework
       0x100a40000 -        0x101c73fff com.Comatherm.Comos (*) <0534df7f-f4f8-3ee9-b9eb-bdba8f4a33e8> /Applications/Comos/Comos.app/Contents/MacOS/Comos
       0x10233c000 -        0x10239bfff dyld (*) <7e92b284-4b90-3b68-b31a-3ddc4c0e8d40> /usr/lib/dyld
       0x18df6c000 -        0x18dfa1fff libsystem_kernel.dylib (*) <c8b3081a-5081-3a99-bbe3-01413de444c6> /usr/lib/system/libsystem_kernel.dylib
       0x18dff0000 -        0x18e533fff com.apple.CoreFoundation (6.9) <f5ea9592-4ef9-3d35-b23d-5c21283acc52> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x18dfa2000 -        0x18dfaefff libsystem_pthread.dylib (*) <ed328b18-eeef-3b15-8858-798b19b0c2cd> /usr/lib/system/libsystem_pthread.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

The menubar is having a hissy fit. Since Matt Neuburg’s time I’ve been using a trick for modals or modal sheets. The modal is responsible for showing and hiding itself.

dim theSearchWindow as new SearchWindow
dim searchResult as Dictionary = theSearchWindow.init(self, globals.thePrefs.GetPrefString("Search"), UsersAndMailboxes, theMailboxesUI)

The init method:

Public Function init(theWindow as Window, SearchString as String, hasUsersAndMailboxes() as String, hasMailboxesUI() as String) As Dictionary
    
'do some initialisation
  
  self.ShowModalWithin(theWindow)
  
  Return SearchResult
  
End Function

There must be a button which sets the result and closes the modal window. This works fine even on Monterey.

2 Likes

Thanks! You steered me in the right direction by stating that the menubar was the culprit. I changed my code to your example, but it was still crashing. Strange thing is that I also use this ShowModal method in more places in my app and every other example is working without crashing…

So I also looked around in the Inspector and found “Menu bar visible” under Deprecated. I switched this setting off and my crash is gone!

2 Likes

Just keep in mind that turning this off really does make the menu bar invisible. Keyboard shortcut commands still work, but there’s nothing to pull down.

Yes, I understand that. But I only use that when the SearchCustomer is active, so whenever the focus shifts on the real work screen, the menu pops back. And I really needed to tackle this error since we were already working with some of the newer Apple Silicon machines that had this bug :wink:

@Beatrix_Willius Are you suggesting that there is a widespread issue with opening Modal and Sheet windows. I’d never come across it until I read this thread. Then as if my magic I suddenly got something that felt like this. Using your .init trick seems to have solved the problem.

The app has 20+ windows and only 1 of them, in 1 circumstance ran into this issue, and only if I attempted to delete a certain file after closure. I’m wondering if this is a wider issue I should address now or just for this one problem area.

This is the start of my crash report. It also seems that it happens all the time in the debugger, but not when I don’t put any breakpoints on the code.

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               myapp.debug [75454]
Path:                  /Users/USER/Documents/*/myapp.debug.app/Contents/MacOS/myapp.debug
Identifier:            myapp.debug
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               504

Date/Time:             2022-02-05 00:23:19.0814 +0000
OS Version:            macOS 12.2 (21D49)
Report Version:        12
Anonymous UUID:        F92937B4-B744-046A-E67E-AC0DEC19787D

Sleep/Wake UUID:       632685FD-32D5-4CAF-96A4-B65FF1B668F1

Time Awake Since Boot: 150000 seconds
Time Since Wake:       22019 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 0x65696669746e6660 -> 0x00006669746e6660 (possible pointer authentication failure)
Exception Codes:       0x0000000000000001, 0x65696669746e6660
Exception Note:        EXC_CORPSE_NOTIFY

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

VM Region Info: 0x6669746e6660 is not in any region.  Bytes after previous region: 7048920983137  
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_NANO              600038000000-600040000000 [128.0M] rw-/rwx SM=PRV  
--->  
      UNUSED SPACE AT END

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   XojoFramework                 	       0x10760ce50 RuntimeShowModalWithinWindow + 320
1   XojoFramework                 	       0x10760ceb0 RuntimeShowModalWithinWindow + 416
2   C-Stat.debug                  	       0x104edc6d0 DesktopWindow.ShowModal%%o<DesktopWindow>o<DesktopWindow> + 108
3   C-Stat.debug                  	       0x105050100 CSW.CSW._FilePrint_Action%b%o<CSW.CSW> + 5180 (/CSW:2033)
4   XojoFramework                 	       0x10755565c InvokeMenuHandler(RunMenuItem*, unsigned char, Window*, unsigned char&) + 1012

My issue looks to be similar to this bug report:

<https://xojo.com/issue/49899>

Hmm, still not solved after all. It seems that this behavior is also present with other Document windows with similar calls. The program crashes with the Search window active, when I temporary switch to another program and go back to my program, all with the Search window open.

I’d inspect code, if any, in the activate / deactivate events of all the opened windows of my app.

Then, I build a sample project froms cratch to display the (bad) behavior.

a. the bug is present,

b.no more bug,

c. I discovered where the bug lie in the process.

and if the bug is still present, you have a project to share (here / in a bug report, eventually).

This is happening in our app too, on both Intel and Apple Silicon on Monterey. We are getting more and more reports each day from customers, and it’s becoming a serious issue. Is Xojo looking into this?

I think my problem comes from the fact that my project is very old and started on Realbasic in 2003. The project kept developing and recently I had to switch to the latest version of Xojo because of the fact that our company is moving to Apple Silicon machines. Because of that I still have a lot of deprecated code and maybe some ways of doing things that are not optimal in the new Xojo.

I found a workaround, although not a satisfying solution yet. I changed my Searchwindow from a Document window to a Movable Modal window and also set “Menu Bar visible” to False, since I noticed that is the standard way for a Movable Modal. This keeps the Search window “connected” to the window it is called from and pushes the user to complete the search task before doing something else and leave the search window open. This prevents the program from crashing, which usually happens when people switch to another program with the search window open. The crash happens as soon as people return to my program.

1 Like

Problem is that Xojo is not throwing an error, but the app (or the debugger) just crash with an Apple crash report. This makes it very hard to find the origin of the bug.

This is most probably a system bug.

The way I solved it is by looking at the Xojo Example projects and try to find something that did the same as what I needed: open a new window that has the user make a choice that was sent back to the main window.

I found the CalendarWindow project to be of great help. I found out that this sample project uses a Movable Modal window as the search window, while I use a Document window (that allows the user to start a search, but then wander off to do other things with my software, leaving the search window open). This forces the search window to the top until you select something, after this you can continue using the software. This makes working with my software a little more rigor, but it also prevents the user closing the main windows from which the search windows was launched (causing an error?).

After this, I replaced all my windows that have this sort of search & select function by Movable Modal windows. I also needed to set “Menu Bar Visible” to False (otherwise still crashes), but I believe that is a deprecated function. No more crashes up until this moment and crossing my fingers.

1 Like

Switching from Document window type to Floating Window appears like it may fix it, even with calling Window.ShowModal. I will test it out more and see if this is the case.

Some thoughts on this.

  1. Apple’s own APIs don’t work like Xojo’s, For instance when you call a NSOpenPanel, NSSavePanel or NSAlert, it doesn’t pause thread execution. Instead once they’re closed, they use a callback to fire a method within your application (except NSAlert does have a show modal, but not show modal within).
    I believe that Xojo is using some trickery to make it work the way it does, something that was accepted under the macOS, but isn’t correctly implemented under iOS.

  2. The macOS on ARM is one step closer to iOS than ever before, yes I know that Federighi said they’re not merging the macOS and iOS, but that statement wasn’t true at the time and still isn’t true today. For instance M1 Macs using iOS constants instead of macOS constants.

  3. It is my understanding that you’re trying to make a document window modal on the macOS, this isn’t consistent with other applications and make explain some issues that were experienced. It would be better for the customer if a Modal window was used as that is consistently the kind of window that’s closed from a button and not the X in the left hand corner.

I hope that this makes sense and helps.

1 Like

This is exactly what I’m suspecting. I’ve experienced this in the past where Apple changed something in macOS that basically broke part of my app and forced me to rethink my design.

P.S. This is affecting Intel too so this appears to be more of a Monterey issue than Apple Silicon.

Its quite sad really, because I know that Apple knows how much more expensive it is for 3rd Party developers to build and maintain apps for their platforms with such a rabid pace of change. While at the same time, Apple needs 3rd Party Developers (in their stores) in-order to improve their services revenue.

I discovered something else and was able to fix it. I called a series of 3 methods to popup this document modal window that was crashing:

  1. OpenTransaction method calls OpenItem method with some parameters

  2. OpenItem method then instantiates the window object and passes it to the OpenWindow method

  3. OpenWindow method finally calls window.showmodal and returns its result.

When I took method #3 OpenWindow and rolled it into method #2 OpenItem, it stopped the crash. Seems that passing the window object around too much may have caused the issue for this particular modal document window? Was never an issue until Monterey.

But so far it works!

Hi, Mario. I am having almost identical problem to yours involving ShowModal. I have made an Issue report #68727, but no success so far with that. As I read your thread, I think I see:

  1. The crash seems associated with the MacOS “Monterey”
  2. Two or three workarounds (but no clear isolation of the root cause).

I hope you can answer my two questions: Is Monterey definitely the culprit? Is your workaround still preventing the crashes?