mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-09 03:16:26 +00:00
audio: Clean up some CloseDevice() interface details.
- It's now always called if device->hidden isn't NULL, even if OpenDevice() failed halfway through. This lets implementation code not have to clean up itself on every possible failure point; just return an error and SDL will handle it for you. - Implementations can assume this->hidden != NULL and not check for it. - implementations don't have to set this->hidden = NULL when done, because the caller is always about to free(this). - Don't reset other fields that are in a block of memory about to be free()'d. - Implementations all now free things like internal mix buffers last, after closing devices and such, to guarantee they definitely aren't in use anymore at the point of deallocation.
This commit is contained in:
@@ -982,9 +982,8 @@ close_audio_device(SDL_AudioDevice * device)
|
||||
if (device->convert.needed) {
|
||||
SDL_FreeAudioMem(device->convert.buf);
|
||||
}
|
||||
if (device->opened) {
|
||||
if (device->hidden != NULL) {
|
||||
current_audio.impl.CloseDevice(device);
|
||||
device->opened = SDL_FALSE;
|
||||
}
|
||||
|
||||
free_audio_queue(device->buffer_queue_head);
|
||||
@@ -1193,7 +1192,10 @@ open_audio_device(const char *devname, int iscapture,
|
||||
close_audio_device(device);
|
||||
return 0;
|
||||
}
|
||||
device->opened = SDL_TRUE;
|
||||
|
||||
/* if your target really doesn't need it, set it to 0x1 or something. */
|
||||
/* otherwise, close_audio_device() won't call impl.CloseDevice(). */
|
||||
SDL_assert(device->hidden != NULL);
|
||||
|
||||
/* See if we need to do any conversion */
|
||||
build_cvt = SDL_FALSE;
|
||||
|
Reference in New Issue
Block a user