瀏覽代碼

wasapi: stop infinite loop in audio thread when recording device is unplugged.

(cherry picked from commit a806a9092bce64665c25b28e5ebdf1b99a376f44)
Ryan C. Gordon 3 周之前
父節點
當前提交
c223c5494d
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/audio/wasapi/SDL_wasapi.c

+ 1 - 1
src/audio/wasapi/SDL_wasapi.c

@@ -592,7 +592,7 @@ static int WASAPI_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen
     UINT32 frames = 0;
     DWORD flags = 0;
 
-    while (device->hidden->capture) {
+    while (device->hidden->capture && !SDL_GetAtomicInt(&device->hidden->device_disconnecting))
         const HRESULT ret = IAudioCaptureClient_GetBuffer(device->hidden->capture, &ptr, &frames, &flags, NULL, NULL);
         if (ret == AUDCLNT_S_BUFFER_EMPTY) {
             return 0;  // in theory we should have waited until there was data, but oh well, we'll go back to waiting. Returning 0 is safe in SDL3.