Search Unity

Editor freezes on second play... How to terminate rogue threads created by a plugin?

Discussion in 'Editor & General Support' started by Airmouse, Jul 5, 2020.

  1. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    107
    Hi, I recently have added a 3rd party .dll plugin to my game so I could connect additional hardware. But one of the .dll files appears to be remaining running even after the editor has stopped playing. The plugin works perfectly well the first time I press play, but after I press stop and play again, the editor then will consistently freeze up. And this means I must restart Unity entirely just to make one change or play a scene twice. I'm sure it is some simple issue on their side, but they have expressed little interest in assisting me with troubleshooting (maybe due to the holiday or other world events) but this is literally destroying my ability to be productive or create cool products.

    I would not be able to repair their .dll without their permission, so I am stuck between a rock and am asking if any Unity guru out here might have a suggestion on a way to forcibly terminated this plugin and "start fresh" without the need to restart the editor completely? And a plea: please for the sake of humanity can somebody help me!!!

    After looking through the plugin's (sparse documentation and) example scripts they provide one hint that shows using an async task for gracefully shutting down their plugin:

    Code (CSharp):
    1.  
    2. //Start the plugin
    3. private async void Start() {
    4.     try
    5.     {
    6.         await peripheral.StartAsync();//Unity Editor will be prone to freezing after iterating this line!
    7. ...
    8. ...
    9. //Stop the plugin
    10. public async void Stop() {
    11.     if (peripheral != null) {
    12.         await peripheral.StopAsync();
    13.         peripheral.Dispose();
    14.         peripheral= null;
    15.     }
    16.  
    17.     GC.Collect();
    18. }
    I noticed if I comment out '
    await peripheral.StartAsync();
    ' from within
    Start()
    then the editor remains stable (however the plugin does not start). But after calling
    StartAsync()
    and then
    StopAsync()
    followed by calling Dispose and restarting the scene the editor still panics and quits:



    This was the only information in the Editor.log which appeared to be relevant:
    Code (csharp):
    1.  
    2. ========== OUTPUTTING STACK TRACE ==================
    3.  
    4. 0x00007FFEC3FCF393 (ntdll) memset
    5. 0x00007FFEC3F83705 (ntdll) RtlExitUserThread
    6. 0x00007FFE576A249A (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\utils\mono-threads-windows.c:515] mono_threads_platform_exit
    7. 0x00007FFE5788321F (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\mini\mini-exceptions.c:2079] mono_handle_exception_internal
    8. 0x00007FFE5797EC25 (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\mini\exceptions-amd64.c:415] mono_amd64_throw_exception
    9.   ERROR: SymGetSymFromAddr64, GetLastError: 'The specified module could not be found.' (Address: 00000175B41E1D0A)
    10.   ERROR: SymGetModuleInfo64, GetLastError: 'A dynamic link library (DLL) initialization routine failed.' (Address: 00000175B41E1D0A)
    11. 0x00000175B41E1D0A ((<unknown>)) (function-name not available)
    12. 0x00007FFE576FD9AF (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\metadata\marshal.c:12418] ftnptr_eh_callback_default
    13.   ERROR: SymGetSymFromAddr64, GetLastError: 'The specified module could not be found.' (Address: 00000175D0AB0933)
    14.   ERROR: SymGetModuleInfo64, GetLastError: 'A dynamic link library (DLL) initialization routine failed.' (Address: 00000175D0AB0933)
    15. 0x00000175D0AB0933 ((<unknown>)) (function-name not available)
    16. 0x00007FFEA0718B6E (BluetoothApis) BluetoothGATTUnregisterEvent
    17. 0x00007FFEA07036CA (BluetoothApis) BthpIsDiscoverableByDefault
    18. 0x00007FFEA07037FD (BluetoothApis) BthpIsDiscoverableByDefault
    19. 0x00007FFEA0713830 (BluetoothApis) BluetoothGATTUnregisterEvent
    20. 0x00007FFEA0713F97 (BluetoothApis) BluetoothGATTUnregisterEvent
    21. 0x00007FFEA0713971 (BluetoothApis) BluetoothGATTUnregisterEvent
    22. 0x00007FFEC3F3849C (ntdll) RtlAcquireSRWLockExclusive
    23. 0x00007FFEC3F36A29 (ntdll) RtlReleaseSRWLockExclusive
    24. 0x00007FFEC13C4034 (KERNEL32) BaseThreadInitThunk
    25. 0x00007FFEC3F83691 (ntdll) RtlUserThreadStart
    26.  
    27. ========== END OF STACKTRACE ===========
    28.  
    Unity Version: 2019.3.9f1

    Is there anything I can do to debug or terminate only the threads being created by this plugin?
     
    Last edited: Jul 5, 2020