fix crash with too many sounds

This commit is contained in:
UnknownShadow200 2018-08-07 10:50:29 +10:00
parent 9208456be9
commit c708cc0582

View File

@ -633,8 +633,8 @@ void Audio_Free(AudioHandle handle) {
if (!ctx->Handle) return; if (!ctx->Handle) return;
ReturnCode result = waveOutClose(ctx->Handle); ReturnCode result = waveOutClose(ctx->Handle);
Mem_Set(ctx, 0, sizeof(struct AudioContext));
ErrorHandler_CheckOrFail(result, "Audio - closing device"); ErrorHandler_CheckOrFail(result, "Audio - closing device");
Mem_Set(ctx, 0, sizeof(struct AudioContext));
} }
struct AudioFormat* Audio_GetFormat(AudioHandle handle) { struct AudioFormat* Audio_GetFormat(AudioHandle handle) {
@ -648,8 +648,10 @@ void Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
/* only recreate handle if we need to */ /* only recreate handle if we need to */
if (AudioFormat_Eq(cur, format)) return; if (AudioFormat_Eq(cur, format)) return;
if (ctx->Handle) Audio_Free(handle); if (ctx->Handle) {
ctx->Format = *format; ReturnCode result = waveOutClose(ctx->Handle);
ErrorHandler_CheckOrFail(result, "Audio - closing device");
}
WAVEFORMATEX fmt = { 0 }; WAVEFORMATEX fmt = { 0 };
fmt.nChannels = format->Channels; fmt.nChannels = format->Channels;
@ -662,6 +664,7 @@ void Audio_SetFormat(AudioHandle handle, struct AudioFormat* format) {
if (waveOutGetNumDevs() == 0u) ErrorHandler_Fail("No audio devices found"); if (waveOutGetNumDevs() == 0u) ErrorHandler_Fail("No audio devices found");
ReturnCode result = waveOutOpen(&ctx->Handle, WAVE_MAPPER, &fmt, NULL, NULL, CALLBACK_NULL); ReturnCode result = waveOutOpen(&ctx->Handle, WAVE_MAPPER, &fmt, NULL, NULL, CALLBACK_NULL);
ErrorHandler_CheckOrFail(result, "Audio - opening device"); ErrorHandler_CheckOrFail(result, "Audio - opening device");
ctx->Format = *format;
} }
void Audio_PlayData(AudioHandle handle, Int32 idx, void* data, UInt32 dataSize) { void Audio_PlayData(AudioHandle handle, Int32 idx, void* data, UInt32 dataSize) {