What does IDirectSound8::CreateSoundBuffer returning DSERR_BUFFERLOST mean?
According to the documentation DSERR_BUFFERLOST isn't a valid return code from CreateSoundBuffer.
Two of our users have report errors where CreateSoundBuffer is returning DSERR_BUFFERLOST (out of hundreds). We've shipped products with this code to thousands of users without any reported issues. Both users report having latest sound drivers. One reports having an Alienware 17 R4 laptop, the other an MSI laptop.
One user on Windows-10 reported that using Windows-8 compatibility mode fixed this issue.
Other internet references include this link. One user tried restarting their Windows Audio service and it had no effect. This link seems to describe an identical issue in another game.
Here is the rest of the setup for that call:
WAVEFORMATEX w = {};
w.wFormatTag = WAVE_FORMAT_PCM;
w.nSamplesPerSec = pSoundData->sampleRate;
w.wBitsPerSample = (WORD)pSoundData->bitsPerSample;
w.nChannels = (WORD)pSoundData->numChannels;
w.nBlockAlign = w.nChannels * w.wBitsPerSample / 8;
w.nAvgBytesPerSec = w.nSamplesPerSec * w.nBlockAlign;
w.cbSize = 0;
int bufferSize = pSoundData->decodedSize;
int bufferFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_GLOBALFOCUS;
DSBUFFERDESC bufferDesc = { sizeof(DSBUFFERDESC), (DWORD)bufferFlags, (DWORD)bufferSize, 0, &w, DS3DALG_DEFAULT };
LPDIRECTSOUNDBUFFER pBuffer;
HRESULT hr = pSoundInterface->mDevice->CreateSoundBuffer(&bufferDesc, &pBuffer, NULL);
The DirectSound docs haven't been edited in ages, but I can tell you that
DSERR_BUFFERLOSTis a valid error from a number of methods:GetCurrentPosition,Play,Stop,Lock,Unlock, andRestore.DirectSound on all versions of Windows since Windows Vista isn't "direct" at all. It is using Windows Core Audio (WASAPI) to output. The primary reason you get a
DSERR_BUFFERLOSTis whenever you get a 'critical error' from WASAPI. Normally this only happens if you are losing the current playback device, but it's handled internally to switch devices so that really shouldn't be the case here.If you are able to repro this issue, you could try enabling DirectSound ETW events to look for the error code happening here.
Otherwise, it could be a driver or hardware bug at play.