]> Repos - portaudio/commitdiff
Fix: WASAPI should not fail with error if no device found
authorBlue Cat Audio <support@bluecataudio.com>
Thu, 7 Jan 2021 11:24:41 +0000 (12:24 +0100)
committerBlue Cat Audio <support@bluecataudio.com>
Thu, 7 Jan 2021 11:52:09 +0000 (12:52 +0100)
src/hostapi/wasapi/pa_win_wasapi.c

index 39a09db26c9a03e946f1297d92de444d16ef38a5..9273cb6fcccfcce153b19e93a795b9d19d65c4f3 100644 (file)
@@ -2110,7 +2110,7 @@ static PaError CreateDeviceList(PaWasapiHostApiRepresentation *paWasapi, PaHostA
 {
     PaUtilHostApiRepresentation *hostApi = (PaUtilHostApiRepresentation *)paWasapi;
     PaError result = paNoError;
-    PaDeviceInfo *deviceInfoArray;
+    PaDeviceInfo *deviceInfoArray = NULL;
     UINT32 i;
     WCHAR *defaultRenderId = NULL;
     WCHAR *defaultCaptureId = NULL;
@@ -2228,7 +2228,7 @@ static PaError CreateDeviceList(PaWasapiHostApiRepresentation *paWasapi, PaHostA
 #endif
 
     // Allocate memory for the device list
-    if ((deviceInfoArray = AllocateDeviceListMemory(paWasapi)) == NULL)
+    if ((paWasapi->deviceCount != 0) && ((deviceInfoArray = AllocateDeviceListMemory(paWasapi)) == NULL))
     {
         result = paInsufficientMemory;
         goto error;
@@ -2262,7 +2262,7 @@ static PaError CreateDeviceList(PaWasapiHostApiRepresentation *paWasapi, PaHostA
 
     // Fill the remaining slots with inactive device info
 #if defined(PA_WASAPI_MAX_CONST_DEVICE_COUNT) && (PA_WASAPI_MAX_CONST_DEVICE_COUNT > 0)
-    if (hostApi->info.deviceCount < PA_WASAPI_MAX_CONST_DEVICE_COUNT)
+    if ((hostApi->info.deviceCount != 0) && (hostApi->info.deviceCount < PA_WASAPI_MAX_CONST_DEVICE_COUNT))
     {        
         for (i = hostApi->info.deviceCount; i < PA_WASAPI_MAX_CONST_DEVICE_COUNT; ++i)
         {