From 503ce9b825a0edbf3a3586ffcf58d09e9ed9aaa3 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Thu, 4 Jun 2020 22:44:52 -0500 Subject: [PATCH] fix applications using IDirectSoundBuffer_Lock incorrectly --- .../hle/DSOUND/DirectSound/DirectSoundBuffer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp b/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp index b0547dc63..6f83e93c2 100644 --- a/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp +++ b/src/core/hle/DSOUND/DirectSound/DirectSoundBuffer.cpp @@ -465,8 +465,16 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_Lock) if (pThis->Host_lock.pLockPtr2 != nullptr) { *ppvAudioPtr2 = pThis->X_lock.pLockPtr2 = pThis->X_BufferCache; *pdwAudioBytes2 = pThis->X_lock.dwLockBytes2 = DSoundBufferGetXboxBufferSize(pThis->EmuFlags, pThis->Host_lock.dwLockBytes2); - } else if (ppvAudioPtr2 != xbnullptr) { - *ppvAudioPtr2 = xbnullptr; + } else { + // If secondary pointers are not used, then set them as zero. + // There are applications bug didn't check for audio pointer that is null pointer which should not use invalid audio bytes. + // Since internal functions do set them zero. We'll set them here as well. + if (ppvAudioPtr2 != xbnullptr) { + *ppvAudioPtr2 = xbnullptr; + } + if (pdwAudioBytes2 != xbnullptr) { + *pdwAudioBytes2 = 0; + } } RETURN_RESULT_CHECK(hRet);