changeset 49:7e4dae99f919

USBLib: fix unhandled exception in WinUSB shutdown after failure to open device
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 19 Aug 2013 16:56:50 +0200
parents f553f6e0a396
children e3f37686b15a
files USBLib/Communication/WinUsb/WinUsbDevice.cs
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/USBLib/Communication/WinUsb/WinUsbDevice.cs	Tue Jul 16 14:02:33 2013 +0200
+++ b/USBLib/Communication/WinUsb/WinUsbDevice.cs	Mon Aug 19 16:56:50 2013 +0200
@@ -60,7 +60,7 @@
 		//[DllImport(WIN_USB_DLL, SetLastError = true)]
 		//private static extern bool WinUsb_SetPipePolicy(SafeWinUsbInterfaceHandle InterfaceHandle, byte PipeID, UInt32 PolicyType, UInt32 ValueLength, ref Byte Value);
 		SafeFileHandle DeviceHandle;
-		private SafeWinUsbInterfaceHandle[] InterfaceHandles = null;
+		private SafeWinUsbInterfaceHandle[] InterfaceHandles = new SafeWinUsbInterfaceHandle[0];
 		private int[] EndpointToInterfaceIn = new int[0];
 		private int[] EndpointToInterfaceOut = new int[0];
 		public IUsbDeviceRegistry Registry { get; private set; }
@@ -132,7 +132,7 @@
 		}
 
 		public override void Close() {
-			foreach (SafeWinUsbInterfaceHandle ih in InterfaceHandles) ih.Close();
+			foreach (SafeWinUsbInterfaceHandle ih in InterfaceHandles) if (ih != null) ih.Close();
 			InterfaceHandles = new SafeWinUsbInterfaceHandle[0];
 			if (DeviceHandle != null) DeviceHandle.Close();
 		}