NiyaShy / XB1ControllerBatteryIndicator

A tray application that shows a battery indicator for an Xbox-ish controller and gives a notification when the battery level drops to (almost) empty.
GNU General Public License v2.0
710 stars 53 forks source link

Crash after turning off controller #72

Closed samusaran closed 1 year ago

samusaran commented 1 year ago

Hi, I noticed that the application crashed after turning off the controller. Sadly I have nothing more than the event viewer entry:

Application: XB1ControllerBatteryIndicator.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: SharpDX.SharpDXException
   at SharpDX.Result.CheckError()
   at SharpDX.XInput.Controller.GetBatteryInformation(SharpDX.XInput.BatteryDeviceType)
   at XB1ControllerBatteryIndicator.SystemTrayViewModel.RefreshControllerState()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
NiyaShy commented 1 year ago

Hey, is it constantly happening or did it only happen once? Just tried it myself and it didn't crash when I turned my controller off, just returned to "no controller detected". So it could have been a rare edge case where it tried to read the battery state right as the controller disconnects.

samusaran commented 1 year ago

It happened only once but I wanted to let you know. It could be like you said, that I turned off the controller right at the right moment. If needed, I can make you a pull request with just a try ... catch when you call GetBatteryInformation.

I don't think, looking at the code, that anything more could be done.