From 78897b3e955dcfd275c6089c29e40aed99c0c084 Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 3 Jan 2023 19:10:14 +1000 Subject: [PATCH] Don't try using the DirectSound backend if not all APIs are available. This affects Windows 95. It does not appear to have at least one of these functions. This is convenient because the function IDirectSound::CreateSoundBuffer() is failing in my tests and I wasn't able to figure out what was going on. Simply failing context initialization outright is an acceptable solution for now since Windows 95 is such an uncommon target and it can always fall back to WinMM which works. --- miniaudio.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index aca009fb..4c5ef1b6 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -25010,6 +25010,18 @@ static ma_result ma_context_init__dsound(ma_context* pContext, const ma_context_ pContext->dsound.DirectSoundCaptureCreate = ma_dlsym(pContext, pContext->dsound.hDSoundDLL, "DirectSoundCaptureCreate"); pContext->dsound.DirectSoundCaptureEnumerateA = ma_dlsym(pContext, pContext->dsound.hDSoundDLL, "DirectSoundCaptureEnumerateA"); + /* + We need to support all functions or nothing. DirectSound with Windows 95 seems to not work too + well in my testing. For example, it's missing DirectSoundCaptureEnumerateA(). This is a convenient + place to just disable the DirectSound backend for Windows 95. + */ + if (pContext->dsound.DirectSoundCreate == NULL || + pContext->dsound.DirectSoundEnumerateA == NULL || + pContext->dsound.DirectSoundCaptureCreate == NULL || + pContext->dsound.DirectSoundCaptureEnumerateA == NULL) { + return MA_API_NOT_FOUND; + } + pCallbacks->onContextInit = ma_context_init__dsound; pCallbacks->onContextUninit = ma_context_uninit__dsound; pCallbacks->onContextEnumerateDevices = ma_context_enumerate_devices__dsound;