kirurobo / UniWindowController

Makes your Unity window transparent and allows you to drop files
MIT License
298 stars 35 forks source link

isClickThrough on Mac crashes the application #65

Open Kottakji opened 3 months ago

Kottakji commented 3 months ago

With the following code, it crashes.

If I remove _window.isClickThrough = true; it will work just fine.

#if !UNITY_EDITOR && !UNITY_WEBGL && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
using System;
using Kirurobo;
#endif
using UnityEngine;

namespace Scripts.Platforms
{
    public class TransparentWindow : MonoBehaviour
    {

#if !UNITY_EDITOR && !UNITY_WEBGL
        private UniWindowController _window;

        private void Start()
        {
            try
            {
                _window = gameObject.AddComponent<UniWindowController>();
                _window.isHitTestEnabled = false;
                _window.isClickThrough = true;
                _window.isTransparent = true;
                _window.isTopmost = true;
                _window.autoSwitchCameraBackground = true;
                _window.forceWindowed = true;
                _window.currentCamera = Camera.main;
                _window.shouldFitMonitor = true;
            }
            catch (Exception exception)
            {
                Debug.Log(exception.Message);
            }
        }
        private void Update()
        {
            _window.isTopmost = true;
        }
#endif
    }
}
Mono path[0] = '/Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Resources/Data/Managed'
Mono config path = '/Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/MonoBleedingEdge/etc'
[Physics::Module] Initialized MultithreadedJobDispatcher with 7 workers.
Initialize engine version: 2023.2.3f1 (21747dafc6ee)
[Subsystems] Discovering subsystems at path /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Resources/Data/UnitySubsystems
GfxDevice: creating device client; kGfxThreadingModeThreaded
 preferred device: Apple M1 Pro (high power)
Metal devices available: 1
0: Apple M1 Pro (high power)
Using device Apple M1 Pro (high power)
Initializing Metal device caps: Apple M1 Pro
Begin MonoManager ReloadAssembly
icall.c:1842:
icall.c:1842:
icall.c:1842:
icall.c:1842:
icall.c:1842:
icall.c:1842:
icall.c:1842:
icall.c:1842:
icall.c:1842:
- Loaded All Assemblies, in  0.364 seconds
icall.c:1842:
icall.c:1842:
- Finished resetting the current domain, in  0.012 seconds
UnloadTime: 2.718833 ms

=================================================================
        Native Crash Reporting
=================================================================
Got a term while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
        Native stacktrace:
=================================================================
        0x11b87659a - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/libmonobdwgc-2.0.dylib : mono_breakpoint_clean_code
        0x11b81c922 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/libmonobdwgc-2.0.dylib : mono_unity_backtrace_from_context
        0x11b798997 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/libmonobdwgc-2.0.dylib : mono_jit_set_domain
        0x7ff8149b85ed - /usr/lib/system/libsystem_platform.dylib : _sigtramp
        0x0 - Unknown
        0x12b767ec0 - Unknown
        0x127c790c9 - Unknown
        0x11b79bbae - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/libmonobdwgc-2.0.dylib : mono_get_runtime_build_info
        0x11b94faf4 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/libmonobdwgc-2.0.dylib : mono_runtime_invoke
        0x11b94fa58 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/libmonobdwgc-2.0.dylib : mono_runtime_invoke
        0x10ab1db59 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10ab0b9b2 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10aafe445 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10aafec40 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10aaff5d9 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10a75e774 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10a9082cd - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10a90831b - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10a9085c6 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _ZdaPvRKSt9nothrow_t
        0x10b4d2481 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _Z10PlayerMainiPPKc
        0x10b4d22e0 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _Z10PlayerMainiPPKc
        0x7ff81588e8f6 - /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation : __NSFireTimer
        0x7ff814a7fcb2 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
        0x7ff814a7f82f - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFRunLoopDoTimer
        0x7ff814a7f44a - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFRunLoopDoTimers
        0x7ff814a65948 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFRunLoopRun
        0x7ff814a64a4c - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : CFRunLoopRunSpecific
        0x7ff81e996fcd - /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox : RunCurrentEventLoopInMode
        0x7ff81e996dde - /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox : ReceiveNextEventCommon
        0x7ff81e996b38 - /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox : _BlockUntilNextEventMatchingListInModeWithFilter
        0x7ff817a567a0 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : _DPSNextEvent
        0x7ff817a5564a - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
        0x7ff817a47cb8 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication run]
        0x7ff817a1bed2 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : NSApplicationMain
        0x10b4d1ee4 - /Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/Frameworks/UnityPlayer.dylib : _Z10PlayerMainiPPKc
        0x20051d41f - Unknown

=================================================================
        Telemetry Dumper:
=================================================================
Pkilling 0x12987686912x from 0x8595960448x
Pkilling 0x12970242048x from 0x8595960448x
Pkilling 0x12971315200x from 0x8595960448x
Entering thread summarizer pause from 0x8595960448x
Finished thread summarizer pause from 0x8595960448x.
Failed to create breadcrumb file (null)/crash_hash_0x6927d0389
Could not exec mono-hang-watchdog, expected on path '/Users/xxx/projects/myproject/src-tauri/target/debug/bin/osx/overlay.app/Contents/MonoBleedingEdge/etc/../bin/mono-hang-watchdog' (errno 2)

Waiting for dumping threads to resume

=================================================================
        External Debugger Dump:
=================================================================

=================================================================
        Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x108bfc9fc):0x108bfc9ec  00 00 48 8d 35 eb e1 ff ff e8 44 9e 00 00 eb c6  ..H.5.....D.....
0x108bfc9fc  0f 0b 66 90 55 48 89 e5 31 ff 84 d2 40 0f 95 c7  ..f.UH..1...@...
0x108bfca0c  5d e9 be 3b 00 00 66 66 66 66 66 2e 0f 1f 84 00  ]..;..fffff.....
0x108bfca1c  00 00 00 00 55 48 89 e5 5d e9 b6 4e 00 00 66 0f  ....UH..]..N..f.

=================================================================
        Managed Stacktrace:
=================================================================
          at <unknown> <0xffffffff>
          at LibUniWinC:SetClickThrough <0x0006f>
          at Kirurobo.UniWinCore:EnableClickThrough <0x00022>
          at Kirurobo.UniWindowController:SetClickThrough <0x0003a>
          at Kirurobo.UniWindowController:set_isClickThrough <0x00022>
          at Scripts.Platforms.TransparentWindow:Start <0x00082>
          at System.Object:runtime_invoke_void__this__ <0x00088>
=================================================================
Obtained 32 stack frames.
#0  0x00000108bfc9fc in $s10LibUniWinCAAC15setClickThrough13isTransparentySb_tFZTo
#1  0x0000012b767ec0 in  (wrapper managed-to-native) Kirurobo.UniWinCore/LibUniWinC:SetClickThrough (bool) [{0x7fcbcd94af08} + 0x70]  (0x12b767e50 0x12b767f3b) [0x11b4edd20 - Unity Root Domain]
#2  0x00000127c790c9 in  (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) [{0x7fcbce41bbe0} + 0x89]  (0x127c79040 0x127c79163) [0x11b4edd20 - Unity Root Domain]
#3  0x0000011b79bbae in mono_get_runtime_build_info
#4  0x0000011b94faf4 in mono_runtime_invoke
#5  0x0000011b94fa58 in mono_runtime_invoke
#6  0x0000010ab1db59 in operator delete[](void*, std::nothrow_t const&)
#7  0x0000010ab0b9b2 in operator delete[](void*, std::nothrow_t const&)
#8  0x0000010aafe445 in operator delete[](void*, std::nothrow_t const&)
#9  0x0000010aafec40 in operator delete[](void*, std::nothrow_t const&)
#10 0x0000010aaff5d9 in operator delete[](void*, std::nothrow_t const&)
#11 0x0000010a75e774 in operator delete[](void*, std::nothrow_t const&)
#12 0x0000010a9082cd in operator delete[](void*, std::nothrow_t const&)
#13 0x0000010a90831b in operator delete[](void*, std::nothrow_t const&)
#14 0x0000010a9085c6 in operator delete[](void*, std::nothrow_t const&)
#15 0x0000010b4d2481 in PlayerMain(int, char const**)
#16 0x0000010b4d22e0 in PlayerMain(int, char const**)
#17 0x007ff81588e8f6 in __NSFireTimer
#18 0x007ff814a7fcb2 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#19 0x007ff814a7f82f in __CFRunLoopDoTimer
#20 0x007ff814a7f44a in __CFRunLoopDoTimers
#21 0x007ff814a65948 in __CFRunLoopRun
#22 0x007ff814a64a4c in CFRunLoopRunSpecific
#23 0x007ff81e996fcd in RunCurrentEventLoopInMode
#24 0x007ff81e996dde in ReceiveNextEventCommon
#25 0x007ff81e996b38 in _BlockUntilNextEventMatchingListInModeWithFilter
#26 0x007ff817a567a0 in _DPSNextEvent
#27 0x007ff817a5564a in -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
#28 0x007ff817a47cb8 in -[NSApplication run]
#29 0x007ff817a1bed2 in NSApplicationMain
#30 0x0000010b4d1ee4 in PlayerMain(int, char const**)
#31 0x0000020051d41f in (Unknown)
kirurobo commented 2 months ago

Thanks for the report. I have been busy lately and have not been able to check, but I will check back and correct the issue.