Crashes when launching - Range extends past the end of the array
I installed AudioSwitch a few days ago and it worked fine till now - however now it just crashes every time I launch. I've tried uninstalling and re-installing but it's still the same.
This is the error message I see:
System.ArgumentOutOfRangeException: Requested range extends past the end of the array. at System.Runtime.InteropServices.Marshal.CopyToNative(Object source, Int32 startIndex, IntPtr destination, Int32 length) at System.Runtime.InteropServices.Marshal.Copy(Byte[] source, Int32 startIndex, IntPtr destination, Int32 length) at System.Drawing.Icon.BmpFrame() at System.Drawing.Icon.ToBitmap() at AudioSwitch.Classes.DeviceIcons.AddOverlay(Icon originalIcon, Image overlay) at AudioSwitch.Classes.DeviceIcons.Add(String iconPath) at AudioSwitch.Forms.FormSwitcher.RefreshDevices(EDataFlow renderType) at AudioSwitch.Forms.FormSwitcher..ctor() at AudioSwitch.Classes.Program.Main(String[] args)
Actually I have changed icons in some of my Audio devices from the default - could that have anything to do with it?
Yes it could, for example if the icon doesn't correspond to the requirements of the device icon. Be sure to have 24x24, 32x32 and 48x48 sizes in highest colors in your icon file.
On Tue, Jan 5, 2016 at 2:28 PM RedWizard99 [email protected] wrote:
Actually I have changed icons in some of my Audio devices from the default
- could that have anything to do with it?
— Reply to this email directly or view it on GitHub https://github.com/sirWest/AudioSwitch/issues/51#issuecomment-168986198.
Yes, I just tested it and it was the icons, I set them back to ones from the default dll and that's stopped the crashing - I'll have to check out those icons, I just created them through an online converter.
I am running into this exception with no custom icons. I installed it, used it for the evening, then put my computer to sleep. Today, it crashes with this exception on every launch. The only customization I made was to hide some of the devices I don't use. Other than that, it is straight out of the box.
Hmm, now that I read the stack trace, the exception is the same, but it is in a different part of the code related to the tray icons.
Application: AudioSwitch.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentOutOfRangeException
at System.Windows.Forms.ListView+SelectedListViewItemCollection.get_Item(Int32)
at AudioSwitch.Forms.FormSwitcher.<SetTrayIcons>b__29_0(CDevice)
at System.Collections.Generic.List1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Find(System.Predicate1<System.__Canon>)
at AudioSwitch.Forms.FormSwitcher.SetTrayIcons()
at AudioSwitch.Forms.FormSwitcher..ctor()
at AudioSwitch.Classes.Program.Main(System.String[])
Uninstall and reinstall does not seem to fix the problem.
Looks like: var devSettings = Program.settings.Device.Find(x => { var dev = listDevices.SelectedItems[0]; return x.DeviceID == dev.Tag.ToString(); });
Assumes that listDevices isn't an empty array. Not sure how it gets set that way; I didn't dive too deep into it.
My wife figured it out. With two bluetooth devices as the only options, when both are turned off, the app crashes on launch because it has no devices from which to choose. Powering either device on will let the app work as expected. Sounds like it could just use some bounds checking to handle devices coming and going.