hass-agent / HASS.Agent

Unofficial development project for the HASS.Agent platform.
https://hass-agent.io
MIT License
298 stars 7 forks source link

Bug: Hass Agent crashes on switching monitors #132

Open nixtaoz opened 1 month ago

nixtaoz commented 1 month ago

Describe the bug HaaS Agent crashes on my windows 11 machine when I switch from one monitor to another connected monitor

To Reproduce Steps to reproduce the behavior:

  1. Connect a 2nd monitor to PC
  2. Go to 'Windows Settings -> System -> Display'
  3. Select option "Show only on 2"
  4. Wait a couple of seconds
  5. Hass Agent crashes

Expected behavior Does not crash when switching to a 2nd monitor (e.g. connected monitor to connected TV)

Screenshots image

Misc info (please complete the following information): image - Windows' UI language:

Please check what's applicable (multiple answers possible):

Logs

2024-07-25 19:58:31.047 -07:00 [INF] [MAIN] HASS.Agent version: 2.1.0-beta2 2024-07-25 19:58:31.051 -07:00 [INF] [MAIN] Extended logging enabled 2024-07-25 19:58:31.053 -07:00 [INF] [SETTINGS] Config storage path: C:\Users\uxxx\AppData\Local\HASS.Agent\Client\config 2024-07-25 19:58:31.146 -07:00 [INF] [SETTINGS] Configuration loaded 2024-07-25 19:58:31.149 -07:00 [INF] [LOCALIZATION] Selected UI culture: [en] English 2024-07-25 19:58:31.314 -07:00 [DBG] [RADIOMGR] Initialization started 2024-07-25 19:58:31.357 -07:00 [INF] [RADIOMGR] Radio management permission granted 2024-07-25 19:58:31.358 -07:00 [DBG] [RADIOMGR] Enumerating proximity/NFC devices 2024-07-25 19:58:31.369 -07:00 [WRN] [RADIOMGR] Selected NFC reader: 'None' not available 2024-07-25 19:58:31.370 -07:00 [INF] [RADIOMGR] Ready 2024-07-25 19:58:33.403 -07:00 [INF] [INTERNALSENSORS] Ready 2024-07-25 19:58:35.936 -07:00 [FTL] [PROGRAM] FirstChanceException: Specified cast is not valid. System.InvalidCastException: Specified cast is not valid. at WindowsDesktop.Interop.IServiceProvider.QueryService(Guid& guidService, Guid& riid) at WindowsDesktop.Interop.ComInterfaceAssembly.CreateInstance(Type type, Nullable1 guidService) at WindowsDesktop.Interop.ComInterfaceAssembly.CreateInstance(String comInterfaceName, Guid clsid) at WindowsDesktop.Interop.ComWrapperBase1..ctor(ComInterfaceAssembly assembly, Guid clsid) at WindowsDesktop.Interop.Build22621.VirtualDesktopManagerInternal..ctor(ComInterfaceAssembly assembly, ComWrapperFactory factory) at WindowsDesktop.Interop.Build22621.VirtualDesktopProvider22621.InitializeCore(ComInterfaceAssembly assembly) at WindowsDesktop.Interop.VirtualDesktopProvider.Initialize(ComInterfaceAssembly assembly) at WindowsDesktop.VirtualDesktop.InitializeCore() at WindowsDesktop.VirtualDesktop.InitializeIfNeeded() at WindowsDesktop.VirtualDesktop.Configure() at HASS.Agent.Managers.VirtualDesktopManager.Initialize() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent\Managers\VirtualDesktopManager.cs:line 24 2024-07-25 19:58:35.937 -07:00 [ERR] [VIRTDESKT] Error initializing Virtual Desktop Manager, your Windows version may be unsupported 2024-07-25 19:58:35.937 -07:00 [DBG] [AUDIOMGR] initializing 2024-07-25 19:58:36.326 -07:00 [INF] [AUDIOMGR] initialized 2024-07-25 19:58:36.341 -07:00 [INF] [SETTINGS_QUICKACTIONS] Loaded 0 entities 2024-07-25 19:58:36.357 -07:00 [INF] [SETTINGS_COMMANDS] Loaded 5 entities 2024-07-25 19:58:36.382 -07:00 [INF] [SETTINGS_SENSORS] Loaded 3 entities 2024-07-25 19:58:36.441 -07:00 [INF] [LOCALAPI] Disabled 2024-07-25 19:58:36.442 -07:00 [INF] [MQTT] Identifying as device: WINDOWSPC 2024-07-25 19:58:36.443 -07:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey 2024-07-25 19:58:36.447 -07:00 [INF] [MQTT] Connecting .. 2024-07-25 19:58:36.452 -07:00 [INF] [SERVICE] Local install path: C:\Program Files\HASS.Agent Satellite Service\Service\ 2024-07-25 19:58:36.453 -07:00 [INF] [MEDIA] Disabled 2024-07-25 19:58:36.518 -07:00 [INF] [HASS_API] Home Assistant version: 2024.7.3 2024-07-25 19:58:36.570 -07:00 [INF] [NOTIFIER] Ready 2024-07-25 19:58:36.717 -07:00 [INF] [HASS_API] System connected with http://homeassistant.local:8123 2024-07-25 19:58:36.918 -07:00 [INF] [MQTT] Connected 2024-07-25 19:58:38.464 -07:00 [INF] [MQTT] Initial registration completed

`

amadeo-alex commented 1 month ago

I'm yet to reproduce this but looking at the potential cause - Virtual Desktop management library it might be hard to fix. The interesting thing here is also that you appear to have 22H2 which should be supported.

There is also a second option that an obscure audio bug is causing this - other users reported something similar and I think we've fixed it in beta3 (still to be 100% confirmed with broader audience).

Could you please check if there are any windows event viewer logs (errors I suppose) for the time that you reproduce the issue?

In the meantime if you're willing and have time you can test the beta3 bleeding edge build - https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.0-beta3-testbuild1 (please of course back up the config before doing so)

Jefemy commented 1 day ago

I was also having a similar crash when changing windows to display only on my second monitor (Win+P -> Second screen only). Updating to the latest beta appears to have stopped the crash from happening. Is it possible to disable features around virtual desktops? I am purely using this to be able to sleep my pc from homeassistant.

Unsure if you need this since its fixed in the beta but here are the logs from the crash.

Application: HASS.Agent.exe
CoreCLR Version: 6.0.3324.36610
.NET Version: 6.0.33
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidCastException: Specified cast is not valid.
   at WindowsDesktop.Interop.IServiceProvider.QueryService(Guid& guidService, Guid& riid)
   at WindowsDesktop.Interop.ComInterfaceAssembly.CreateInstance(Type type, Nullable`1 guidService)
   at WindowsDesktop.Interop.ComInterfaceAssembly.CreateInstance(String comInterfaceName, Guid clsid)
   at WindowsDesktop.Interop.ComWrapperBase`1..ctor(ComInterfaceAssembly assembly, Guid clsid)
   at WindowsDesktop.Interop.Build22621.VirtualDesktopManagerInternal..ctor(ComInterfaceAssembly assembly, ComWrapperFactory factory)
   at WindowsDesktop.Interop.Build22621.VirtualDesktopProvider22621.InitializeCore(ComInterfaceAssembly assembly)
   at WindowsDesktop.Interop.VirtualDesktopProvider.Initialize(ComInterfaceAssembly assembly)
   at WindowsDesktop.VirtualDesktop.InitializeCore()
   at WindowsDesktop.VirtualDesktop.HandleExplorerRestarted()
   at WindowsDesktop.VirtualDesktop.<>c.<.cctor>b__70_0()
   at WindowsDesktop.Utils.ExplorerRestartListenerWindow.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
Faulting application name: HASS.Agent.exe, version: 2.0.1.0, time stamp: 0x65310000
Faulting module name: KERNELBASE.dll, version: 10.0.22621.4111, time stamp: 0x03c619d0
Exception code: 0xe0434352
Fault offset: 0x000000000005fabc
Faulting process id: 0x0x1BFC
Faulting application start time: 0x0x1DB01306983235F
Faulting application path: C:\Users\Cat\AppData\Local\HASS.Agent\Client\HASS.Agent.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 00c6df40-aa5e-4053-9125-430b41f4bc43
Faulting package full name: 
Faulting package-relative application ID: