diff options
author | Chris Robinson <[email protected]> | 2018-03-08 18:12:14 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-03-08 18:12:14 -0800 |
commit | 52ca70d98e164cb925dcc28fa97ade6fea1bd6ae (patch) | |
tree | 746579e44866426add5be18f160b2876f306dabf /Alc/backends | |
parent | d4fc87fc9c2cacb09d9538c410a701a8dd12aa6b (diff) |
Properly close the SDL2 audio device
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/sdl2.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Alc/backends/sdl2.c b/Alc/backends/sdl2.c index 416e745d..df4324ad 100644 --- a/Alc/backends/sdl2.c +++ b/Alc/backends/sdl2.c @@ -42,7 +42,7 @@ typedef struct ALCsdl2Backend { } ALCsdl2Backend; static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device); -static DECLARE_FORWARD(ALCsdl2Backend, ALCbackend, void, Destruct) +static void ALCsdl2Backend_Destruct(ALCsdl2Backend *self); static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name); static ALCboolean ALCsdl2Backend_reset(ALCsdl2Backend *self); static ALCboolean ALCsdl2Backend_start(ALCsdl2Backend *self); @@ -63,6 +63,7 @@ static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device) ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); SET_VTABLE2(ALCsdl2Backend, ALCbackend, self); + self->deviceID = 0; self->quit = ALC_FALSE; self->Frequency = device->Frequency; self->FmtChans = device->FmtChans; @@ -76,6 +77,18 @@ static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device) SDL_InitSubSystem(SDL_INIT_AUDIO); } +static void ALCsdl2Backend_Destruct(ALCsdl2Backend *self) +{ + if(self->deviceID) + SDL_CloseAudioDevice(self->deviceID); + self->deviceID = 0; + + if(self->quit) + SDL_Quit(); + + ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); +} + static void ALCsdl2Backend_audioCallback(void *ptr, Uint8* stream, int len) { @@ -166,8 +179,6 @@ static ALCboolean ALCsdl2Backend_start(ALCsdl2Backend *self) static void ALCsdl2Backend_stop(ALCsdl2Backend *self) { SDL_PauseAudioDevice(self->deviceID, 1); - if(self->quit) - SDL_Quit(); } @@ -224,7 +235,7 @@ static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enu num_devices = SDL_GetNumAudioDevices(SDL_FALSE); AppendAllDevicesList(defaultDeviceName); - for(i = 0; i < num_devices; ++i) + for(i = 0;i < num_devices;++i) AppendAllDevicesList(SDL_GetAudioDeviceName(i, SDL_FALSE)); if(quit) |