Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

App crashes on Mac when trying to start a thread

Discussion in 'Scripting' started by OscarCybernetic, Oct 15, 2019.

  1. OscarCybernetic

    OscarCybernetic

    Joined:
    Sep 12, 2018
    Posts:
    23
    I'm working with Unity 2018 and I'm using a thread to open the file browser of the respective OS. This works perfectly fine on Windows, but on Mac, it fails and crashes.

    I'm using System.Threading to run the thread. There's only ever one thread at a time. and a UI cover prevents the user from trying to open another browser (and therefore another thread)

    Code (CSharp):
    1.  
    2.     Thread FileBrowserThread;
    3.     //These bools are used by other classes to know the Thread state
    4.     public bool isRunningThread = false;
    5.     public bool IsThreadComplete = false;
    6.  
    7.     private void StartThread(){
    8.         isRunningThread = true;
    9.         IsThreadComplete = false;
    10.         FileBrowserThread = new Thread(() => OpenSingleFolderThread(title, path));
    11.         StartCoroutine(WaitToJoinThread());
    12.         FileBrowserThread.Start();
    13.     }
    14.  
    15.     private void OpenSingleFolderThread(string title, string path)
    16.     {
    17.         isRunningThread = true;
    18.         //code waits here until the filebrowser is closed
    19.         SinglePath = FileBrowser.OpenSingleFolder(title, path);
    20.         isRunningThread = false;
    21.     }
    22.  
    23.     private IEnumerator WaitToJoinThread()
    24.     {
    25.         yield return new WaitUntil(() => isRunningThread == false);
    26.  
    27.         if(FileBrowserThread != null)
    28.         {
    29.             FileBrowserThread.Join();
    30.             FileBrowserThread = null;
    31.         }
    32.         IsThreadComplete = true;
    33.     }
    34.  
    I use threads so that the program does not lock up while the browser is open. Again, this works perfectly on Windows, but Mac keeps failing both in the Editor and in builds. Any ideas or explanations would be appreciated

    Through Debugging, I found that it crashes on FileBrowserThread.Start();

    Process: Unity [44954]
    Path: /Users/USER/Desktop/*/Unity.app/Contents/MacOS/Unity
    Identifier: com.unity3d.UnityEditor5.x
    Version: Unity version 2018.4.2f1 (2018.4.2f1)
    Code Type: X86-64 (Native)
    Parent Process: Unity Hub [699]
    Responsible: Unity [44954]
    User ID: 501

    Date/Time: 2019-10-15 13:07:54.044 -0500
    OS Version: Mac OS X 10.14.6 (18G95)
    Report Version: 12
    Anonymous UUID: 12A583D8-1566-AA5D-7C7A-B19547EB16E3

    Sleep/Wake UUID: 8040C50D-A424-4852-A384-59F76EDF1AC7

    Time Awake Since Boot: 1700000 seconds
    Time Since Wake: 1700000 seconds

    System Integrity Protection: enabled

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

    Exception Type: EXC_BAD_ACCESS (SIGABRT)
    Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018
    Exception Note: EXC_CORPSE_NOTIFY

    VM Regions Near 0x18:
    -->
    __TEXT 0000000100000000-0000000104a21000 [ 74.1M] r-x/rwx SM=COW /Users/USER/Desktop/*/Unity.app/Contents/MacOS/Unity

    Application Specific Information:
    abort() called

    Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
    0 libsystem_kernel.dylib 0x00007fff70b0f2c6 __pthread_kill + 10
    1 libsystem_pthread.dylib 0x00007fff70bcabf1 pthread_kill + 284
    2 libsystem_c.dylib 0x00007fff70a796a6 abort + 127
    3 com.unity3d.UnityEditor5.x 0x0000000101050161 HandleSignal(int, __siginfo*, void*) + 81
    4 libmonobdwgc-2.0.dylib 0x000000014228a375 mono_chain_signal + 79
    5 libmonobdwgc-2.0.dylib 0x000000014215be13 mono_sigsegv_signal_handler + 414
    6 libsystem_platform.dylib 0x00007fff70bbfb5d _sigtramp + 29
    7 ??? 000000000000000000 0 + 0
    8 com.apple.Foundation 0x00007fff46d5fde2 __NSIndexSetEnumerate + 706
    9 com.apple.Foundation 0x00007fff46d5de6c _chooseOutgoingRowHeadForIncomingRowHead + 360
    10 com.apple.Foundation 0x00007fff46d5d92f _minimizeConstantInObjectiveRow + 232
    11 com.apple.Foundation 0x00007fff46d61163 -[NSISEngine _optimizeWithoutRebuilding] + 230
    12 com.apple.Foundation 0x00007fff46d60fe8 -[NSISEngine optimize] + 108
    13 com.apple.Foundation 0x00007fff46d60e4f -[NSISEngine performPendingChangeNotificationsForItem:] + 33
    14 com.apple.AppKit 0x00007fff42161395 -[NSView(NSConstraintBasedLayout) _updateAutoresizingConstraints] + 240
    15 com.apple.AppKit 0x00007fff4215c193 -[NSView updateConstraints] + 88
    16 com.apple.AppKit 0x00007fff4215c121 _NSViewUpdateConstraints + 45
    17 com.apple.AppKit 0x00007fff4215bc8e -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 819
    18 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    19 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    20 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    21 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    22 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    23 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    24 com.apple.AppKit 0x00007fff4215bad9 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 382
    25 com.apple.AppKit 0x00007fff4215c027 __82-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:]_block_invoke + 245
    26 com.apple.Foundation 0x00007fff46d556a7 -[NSISEngine withBehaviors:performModifications:] + 110
    27 com.apple.AppKit 0x00007fff4215ba13 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 184
    28 com.apple.AppKit 0x00007fff4215b863 __45-[NSView updateConstraintsForSubtreeIfNeeded]_block_invoke + 48
    29 com.apple.Foundation 0x00007fff46d556a7 -[NSISEngine withBehaviors:performModifications:] + 110
    30 com.apple.AppKit 0x00007fff420ec294 -[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 70
    31 com.apple.AppKit 0x00007fff4215b218 -[NSView updateConstraintsForSubtreeIfNeeded] + 197
    32 com.apple.AppKit 0x00007fff4215b02b __62-[NSWindow(NSConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke + 154
    33 com.apple.Foundation 0x00007fff46d556a7 -[NSISEngine withBehaviors:performModifications:] + 110
    34 com.apple.AppKit 0x00007fff420ec294 -[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 70
    35 com.apple.AppKit 0x00007fff4215af37 -[NSWindow(NSConstraintBasedLayout) updateConstraintsIfNeeded] + 232
    36 com.apple.AppKit 0x00007fff42174df0 -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 83
    37 com.apple.AppKit 0x00007fff42179398 -[NSWindow displayIfNeeded] + 177
    38 com.apple.AppKit 0x00007fff42179240 __NSWindowGetDisplayCycleObserverForDisplay_block_invoke + 684
    39 com.apple.AppKit 0x00007fff42174334 NSDisplayCycleObserverInvoke + 162
    40 com.apple.AppKit 0x00007fff42173eb4 NSDisplayCycleFlush + 1030
    41 com.apple.QuartzCore 0x00007fff4f4e554d CA::Transaction::run_commit_handlers(CATransactionPhase) + 49
    42 com.apple.QuartzCore 0x00007fff4f4e4d26 CA::Transaction::commit() + 212
    43 com.apple.AppKit 0x00007fff4217384d __65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke + 274
    44 com.apple.CoreFoundation 0x00007fff44ad8f28 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    45 com.apple.CoreFoundation 0x00007fff44ad8e5d __CFRunLoopDoObservers + 451
    46 com.apple.CoreFoundation 0x00007fff44a7b580 __CFRunLoopRun + 1136
    47 com.apple.CoreFoundation 0x00007fff44a7aebe CFRunLoopRunSpecific + 455
    48 com.apple.HIToolbox 0x00007fff43cda1ab RunCurrentEventLoopInMode + 292
    49 com.apple.HIToolbox 0x00007fff43cd9ee5 ReceiveNextEventCommon + 603
    50 com.apple.HIToolbox 0x00007fff43cd9c76 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    51 com.apple.AppKit 0x00007fff4207279d _DPSNextEvent + 1135
    52 com.apple.AppKit 0x00007fff4207148b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
    53 com.apple.AppKit 0x00007fff4206b5a8 -[NSApplication run] + 699
    54 com.apple.AppKit 0x00007fff4205aae8 NSApplicationMain + 777
    55 com.unity3d.UnityEditor5.x 0x000000010072875c EditorMain(int, char const**) + 844
    56 com.unity3d.UnityEditor5.x 0x0000000100728bd9 main + 9
    57 libdyld.dylib 0x00007fff709d43d5 start + 1

    Thread 0 crashed with X86 Thread State (64-bit):
    rax: 0x0000000000000000 rbx: 0x000000010f1505c0 rcx: 0x000000013c4e5828 rdx: 0x0000000000000000
    rdi: 0x0000000000000307 rsi: 0x0000000000000006 rbp: 0x000000013c4e5860 rsp: 0x000000013c4e5828
    r8: 0x00000000000000f1 r9: 0x0000000000000000 r10: 0x0000000000000000 r11: 0x0000000000000206
    r12: 0x0000000000000307 r13: 0x0000000000000000 r14: 0x0000000000000006 r15: 0x000000000000002d
    rip: 0x00007fff70b0f2c6 rfl: 0x0000000000000206 cr2: 0x00007fffa7261188

    Logical CPU: 0
    Error Code: 0x02000148
    Trap Number: 133

    External Modification Summary:
    Calls made by other processes targeting this process:
    task_for_pid: 35
    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: 107498017
    thread_create: 0
    thread_set_state: 0

    VM Region Summary:
    ReadOnly portion of Libraries: Total=710.9M resident=0K(0%) swapped_out_or_unallocated=710.9M(100%)
    Writable regions: Total=1.9G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.9G(100%)

    VIRTUAL REGION
    REGION TYPE SIZE COUNT (non-coalesced)
    =========== ======= =======
    Accelerate framework 128K 1
    Activity Tracing 256K 1
    CG backing stores 66.8M 3
    CG image 76K 3
    CoreAnimation 444K 17
    CoreGraphics 8K 1
    CoreImage 24K 2
    CoreUI image data 1516K 16
    CoreUI image file 528K 4
    Dispatch continuations 12.0M 1
    Foundation 4K 1
    Image IO 256K 1
    Kernel Alloc Once 8K 1
    MALLOC 1.4G 264
    MALLOC guard page 32K 7
    MALLOC_LARGE (reserved) 66.8M 7 reserved VM address space (unallocated)
    Memory Tag 242 12K 1
    Memory Tag 255 547.5M 25
    Memory Tag 255 (reserved) 140K 4 reserved VM address space (unallocated)
    STACK GUARD 504K 91
    Stack 160.8M 99
    Stack Guard 56.1M 7
    VM_ALLOCATE 119.8M 126
    VM_ALLOCATE (reserved) 128.1M 3 reserved VM address space (unallocated)
    __DATA 50.6M 398
    __FONT_DATA 4K 1
    __LINKEDIT 281.4M 37
    __TEXT 429.5M 377
    __UNICODE 564K 1
    mapped file 105.1M 182
    shared memory 2788K 16
    =========== ======= =======
    TOTAL 3.4G 1698
    TOTAL, minus reserved VM space 3.2G 1698

    Model: iMac19,2, BootROM 220.270.93.0.0, 6 processors, Intel Core i5, 3 GHz, 8 GB, SMC 2.47f2
    Graphics: kHW_AMDRadeonPro560XItem, Radeon Pro 560X, spdisplays_pcie_device, 4 GB
    Memory Module: BANK 0/ChannelA-DIMM0, 4 GB, DDR4, 2667 MHz, Micron, 4ATF51264HZ-2G6E3
    Memory Module: BANK 2/ChannelB-DIMM0, 4 GB, DDR4, 2667 MHz, Micron, 4ATF51264HZ-2G6E3
    AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x7BF), wl0: Mar 28 2019 19:17:52 version 9.137.9.0.32.6.34 FWID 01-36f56c94
    Bluetooth: Version 6.0.14d3, 3 services, 27 devices, 1 incoming serial ports
    Network Service: Ethernet, Ethernet, en0
    Network Service: Wi-Fi, AirPort, en1
    Serial ATA Device: APPLE HDD HTS541010A9E632, 1 TB
    USB Device: USB 3.1 Bus
    USB Device: FaceTime HD Camera (Built-in)
    USB Device: Magic Keyboard
    Thunderbolt Bus: iMac, Apple Inc., 42.1
     
    Last edited: Oct 15, 2019
  2. OscarCybernetic

    OscarCybernetic

    Joined:
    Sep 12, 2018
    Posts:
    23
    Never mind. The error has to do with the plugin I'm making the thread call