Fix DSoundBufferResizeSetSize with DSBuffer creation failure when remained hos buffer bytes is less then DSBSIZE_MIN, also correct a wrongly used argument with call to DSound3DBufferCreate. add more sanity checks. this fixs PGR2, now release build can enter the race. but debug build has different issue with vector/iterator.

This commit is contained in:
jackchentwkh 2021-05-23 15:58:39 +08:00
parent da7a917ec5
commit 6bb0234dc8
1 changed files with 27 additions and 12 deletions

View File

@ -371,12 +371,19 @@ static inline void DSoundGenericUnlock(
static inline HRESULT DSoundBufferCreate(LPDSBUFFERDESC pDSBufferDesc, LPDIRECTSOUNDBUFFER8 &pDSBuffer)
{
LPDIRECTSOUNDBUFFER pTempBuffer;
//Todo:shall we check the pDSBufferDesc->dwBufferBytes with legal ranges between DSBSIZE_MIN and DSBSIZE_MAX again?
HRESULT hRetDS = g_pDSound8->CreateSoundBuffer(pDSBufferDesc, &pTempBuffer, nullptr);
if (hRetDS == DS_OK) {
hRetDS = pTempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&(pDSBuffer));
pTempBuffer->Release();
}
if (hRetDS == DS_OK) {
hRetDS = pTempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&(pDSBuffer));
pTempBuffer->Release();
if (pDSBuffer == nullptr) {
EmuLog(LOG_LEVEL::WARNING, "CreateSoundBuffer:QueryInterface Failed!");
}
}
else {
EmuLog(LOG_LEVEL::WARNING, "CreateSoundBuffer Failed!");
}
return hRetDS;
}
@ -456,13 +463,17 @@ static inline void DSoundBufferReCreate(
xbox::CDirectSoundVoice* Xb_Voice) {
DSoundBufferCreate(&DSBufferDesc, pDSBufferNew);
if (pDS3DBuffer != nullptr) {
HRESULT hretDS = DSoundBufferCreate(&DSBufferDesc, pDSBufferNew);
//create new DS3DBuffer from the new DSBuffer if the new DSBuffer is created successfully.
if (pDSBufferNew != nullptr) {
DSound3DBufferCreate(pDSBufferNew, pDS3DBufferNew);
}
DSoundBufferTransferSettings(pDSBuffer, pDSBufferNew, pDS3DBuffer, pDS3DBufferNew, Xb_Voice);//Sanity checks inside.
}
else {
EmuLog(LOG_LEVEL::WARNING, "DSoundBufferReCreate Failed!");
}
DSoundBufferTransferSettings(pDSBuffer, pDSBufferNew, pDS3DBuffer, pDS3DBufferNew, Xb_Voice);
}
static inline void DSoundBufferRelease(
@ -503,8 +514,12 @@ static inline void DSoundBufferResizeSetSize(
return;
}
pThis->EmuBufferDesc.dwBufferBytes = Host_dwByteLength;
if (Host_dwByteLength< DSBSIZE_MIN) { //the min. buffer bytes must be equal or greater then DSBSIZE_MIN
pThis->EmuBufferDesc.dwBufferBytes = DSBSIZE_MIN;
}
else {
pThis->EmuBufferDesc.dwBufferBytes = Host_dwByteLength;
}
// NOTE: Test case JSRF, if we allow to re-alloc without checking allocated buffer size.
// Then it is somehow binded to IDirectSound_SetPosition control for any allocated audio afterward.
@ -534,7 +549,7 @@ static inline void DSoundBufferResizeUpdate(
DWORD Xb_dwByteLength) {
xbox::EmuDirectSoundBuffer* pThis = pHybridThis->emuDSBuffer;
DSoundBufferResizeSetSize(pHybridThis, hRet, Xb_dwByteLength);
DSoundBufferResizeSetSize(pHybridThis, hRet, Xb_dwByteLength);
hRet = pThis->EmuDirectSoundBuffer8->Lock(0, 0, &pThis->Host_lock.pLockPtr1, &pThis->Host_lock.dwLockBytes1,
nullptr, nullptr, DSBLOCK_ENTIREBUFFER);