hass-agent / HASS.Agent

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

Bug: HASS.Agent crashes as soon as I run Civilization 5 #115

Open knezmilos13 opened 1 month ago

knezmilos13 commented 1 month ago

HASS.Agent crashes as soon as I run Civilization 5. It also crashes if I run Civ 5, alt+tab to desktop, start HASS.Agent again, then alt+tab back to Civ 5 for a second. Crashes are silent, and there's nothing interesting in the regular log file, however, some stuff appears when more detailed logging is turned on. This is the section of log file that appears after running Civ 5; entire file provided at the bottom.

System.Runtime.InteropServices.COMException (0x80070490): Element not found. (0x80070490)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at CoreAudio.MMDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow dataFlow, Role role)
   at HASS.Agent.Shared.HomeAssistant.Sensors.GeneralSensors.MultiValue.AudioSensors.HandleAudioInputSensors(String parentSensorSafeName, String deviceName) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\HomeAssistant\Sensors\GeneralSensors\MultiValue\AudioSensors.cs:line 127
   at HASS.Agent.Shared.HomeAssistant.Sensors.GeneralSensors.MultiValue.AudioSensors.UpdateSensorValues() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\HomeAssistant\Sensors\GeneralSensors\MultiValue\AudioSensors.cs:line 177
2024-07-11 00:53:22.929 +02:00 [INF] [MQTT] Initial registration completed
2024-07-11 00:55:42.120 +02:00 [FTL] [PROGRAM] FirstChanceException: The method or operation is not implemented.
System.NotImplementedException: The method or operation is not implemented.
   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)
   at WindowsDesktop.Interop.ComWrapperBase`1..ctor(ComInterfaceAssembly assembly)
   at WindowsDesktop.Interop.Build10240.ApplicationViewCollection..ctor(ComInterfaceAssembly assembly)
   at WindowsDesktop.Interop.Build10240.VirtualDesktopProvider10240.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)
2024-07-11 00:55:42.121 +02:00 [FTL] [MAIN] ThreadException: The method or operation is not implemented.
System.NotImplementedException: The method or operation is not implemented.
   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)
   at WindowsDesktop.Interop.ComWrapperBase`1..ctor(ComInterfaceAssembly assembly)
   at WindowsDesktop.Interop.Build10240.ApplicationViewCollection..ctor(ComInterfaceAssembly assembly)
   at WindowsDesktop.Interop.Build10240.VirtualDesktopProvider10240.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)

To Reproduce Steps to reproduce the behavior:

  1. Run Civilization 5
  2. HASS.Agent silently crashes

Misc info (please complete the following information):

Logs [2024-07-11] HASS.Agent_20240711.log

amadeo-alex commented 1 month ago

I must say, that's hell of a issue title :D I think that the crash root cause lies with virtual desktop management library - IoT Enterprise LTSC is not the most used OS version (although I have daily run LTSC for years before so I'm not surprised that you use it) and might not be supported by it. Not sure though how it might be connected to Civ.

Most likely "duplicate" of https://github.com/hass-agent/HASS.Agent/issues/86 and not really fixable on our side. But I might have a fix for you:

Please try if you're comfortable with it. I've created a PR to the library that we're using but unfortunately it didn't get any traction - https://github.com/Slion/VirtualDesktop/pull/24

knezmilos13 commented 1 month ago

An update relating to this bug - literally - I've updated to Windows 11 IoT Enterprise LTSC 24H2 that's conveniently became available recently, and now HASS.Agent no longer crashes.

Something to note - I don't think I have been using any virtual desktops. If I understand correctly, virtual desktop is a desktop that is being streamed from another device, possibly from a VM?

amadeo-alex commented 1 month ago

No, virtual desktops are additional "desktops" where you can have separate icons, programs and windows running. For example tou have one for gaming/fun and other for work - multiple programs can be running at the same time but on different desktops.

The virtual desktop library needs to talk with a lot of system com objects so all window/desktop changes on "non-compatible" os versions can cause issues.