Skip to content

Commit

Permalink
SDL_audio.c: Fix crash if we switch from direct output to streaming, …
Browse files Browse the repository at this point in the history
…and if the buffersizes change.
  • Loading branch information
Felix committed Jan 4, 2024
1 parent 41bf6b5 commit 4482a01
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/audio/SDL_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,19 +703,23 @@ static int SDLCALL SDL_RunAudio(void *userdata)

/* Fill the current buffer with sound */
if (!device->stream && SDL_AtomicGet(&device->enabled)) {
SDL_assert(data_len == device->spec.size);
data = current_audio.impl.GetDeviceBuf(device);

if (device->stream && SDL_AtomicGet(&device->enabled)) {
// Oops. Wasapi reset and now we stream, so just one silence for now
current_audio.impl.PlayDevice(device);
current_audio.impl.WaitDevice(device);
data = device->work_buffer;
} else { // direct output
data_len = device->spec.size;
}
} else {
/* if the device isn't enabled, we still write to the
work_buffer, so the app's callback will fire with
a regular frequency, in case they depend on that
for timing or progress. They can use hotplug
now to know if the device failed.
Streaming playback uses work_buffer, too. */
data = NULL;
}

if (data == NULL) {
data = device->work_buffer;
}

Expand Down

0 comments on commit 4482a01

Please sign in to comment.