Crash in CoreGraphics

My app is crashing in CoreGraphics. As per the observations, it started crashing for Mac OS 14.4 and 14.4.1 on Arm machines. It is observed on multiple machines. Can someone please help on this? Following is the backtrace:

Process:               MyApp [1300]
Path:                  /Applications/MyApp.app/Contents/MacOS/MyApp
Identifier:            com.MyCompany.MyApp
Version:               7.2.3 (???)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               502

Date/Time:             2024-04-23 20:48:08.7647 +0530
OS Version:            macOS 14.4.1 (23E224)
Report Version:        12
Anonymous UUID:        6DAE9C94-37AC-96D0-7221-3AAA99D9E5F6

Sleep/Wake UUID:       03812728-62F0-45A4-86FC-07E151462C11

Time Awake Since Boot: 11000 seconds
Time Since Wake:       1385 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 Codes:       0x0000000000000001, 0x0000000000000008

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

VM Region Info: 0x8 is not in any region.  Bytes before following region: 4338843640
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      1029d8000-1029e4000    [   48K] r-x/r-x SM=COW  /Applications/MyApp.app/Contents/MacOS/MyApp

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreGraphics                  	       0x186aabdac shape_union + 656
1   CoreGraphics                  	       0x186aababc shape_union_with_bounds + 128
2   CoreGraphics                  	       0x186aab9f4 CGRegionCreateUnionWithRect + 240
3   AppKit                        	       0x184b439dc 0x18473e000 + 4217308
4   AppKit                        	       0x184b2ad4c 0x18473e000 + 4115788
5   AppKit                        	       0x184dc358c -[NSViewBackingLayer setNeedsDisplayInRect:] + 176
6   AppKit                        	       0x184790874 -[NSView setNeedsDisplayInRect:] + 396
7   Foundation                    	       0x182070914 __NSThreadPerformPerform + 264
8   CoreFoundation                	       0x180f21eb0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
9   CoreFoundation                	       0x180f21e44 __CFRunLoopDoSource0 + 176
10  CoreFoundation                	       0x180f21bb4 __CFRunLoopDoSources0 + 244
11  CoreFoundation                	       0x180f207a0 __CFRunLoopRun + 828
12  CoreFoundation                	       0x180f1fe0c CFRunLoopRunSpecific + 608
13  HIToolbox                     	       0x18b6bb000 RunCurrentEventLoopInMode + 292
14  HIToolbox                     	       0x18b6bae3c ReceiveNextEventCommon + 648
15  HIToolbox                     	       0x18b6bab94 _BlockUntilNextEventMatchingListInModeWithFilter + 76
16  AppKit                        	       0x184778970 _DPSNextEvent + 660
17  AppKit                        	       0x184f6adec -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700
18  AppKit                        	       0x18476bcb8 -[NSApplication run] + 476
19  libffi.dylib                  	       0x191df8050 ffi_call_SYSV + 80
20  libffi.dylib                  	       0x191e00ae0 ffi_call_int + 1212
21  _objc.cpython-39-darwin.so    	       0x10700a47c PyObjCFFI_Caller_SimpleSEL + 1204
22  _objc.cpython-39-darwin.so    	       0x107034e94 objcsel_vectorcall_simple + 768
23  Python                        	       0x104312ddc call_function + 124
24  Python                        	       0x104311ac0 _PyEval_EvalFrameDefault + 29288
25  Python                        	       0x10427a720 _PyFunction_Vectorcall + 628
26  Python                        	       0x104312ddc call_function + 124
27  Python                        	       0x104311ac0 _PyEval_EvalFrameDefault + 29288
28  Python                        	       0x10427a57c _PyFunction_Vectorcall + 208
29  Python                        	       0x104312ddc call_function + 124
30  Python                        	       0x104311a4c _PyEval_EvalFrameDefault + 29172
31  Python                        	       0x10427a57c _PyFunction_Vectorcall + 208
32  Python                        	       0x104312ddc call_function + 124
33  Python                        	       0x104311ac0 _PyEval_EvalFrameDefault + 29288
34  Python                        	       0x10427a57c _PyFunction_Vectorcall + 208
35  Python                        	       0x104312ddc call_function + 124
36  Python                        	       0x104311aec _PyEval_EvalFrameDefault + 29332
37  Python                        	       0x10427a57c _PyFunction_Vectorcall + 208
38  Python                        	       0x104312ddc call_function + 124
39  Python                        	       0x104311aec _PyEval_EvalFrameDefault + 29332
40  Python                        	       0x1043131a0 _PyEval_EvalCode + 620
41  Python                        	       0x10430a7d0 PyEval_EvalCode + 80
42  MyApp                        	       0x1029dd440 0x1029d8000 + 21568
43  MyApp                        	       0x1029dd7c0 0x1029d8000 + 22464
44  dyld                          	       0x180aba0e0 start + 2360

Hi rksinghal,

The crash log you posted isn't complete (as it stops after the main thread), but one of the main reasons we see this sort of crash is when multiple threads are accessing the AppKit view hierarchy concurrently, which isn't supported. Can you double-check that you're not touching any views (including dirtying them for redisplay) on a background thread?

Thank you. The same code was working fine till now. This is also not crashing on all machines. Only on a very few of them. I was not able to share the complete report due to the text limit. Please refer to the attached file for the complete report.

Crash in CoreGraphics
 
 
Q