Bug causes crash of application which uses that interface for grabbing audio and sometimes it leads to lost of audio signal on speakers.
I implemented my own loopback sound grabbing application which is based on that sample https://learn.microsoft.com/en-us/samples/microsoft/windows-classic-samples/applicationloopbackaudio-sample/
(By the way there is error in implementation of "HRESULT CLoopbackCapture::StopCaptureAsync()" in LoopbackCapture.cpp. If you quickly call HRESULT CLoopbackCapture::StartCaptureAsync() and HRESULT CLoopbackCapture::StopCaptureAsync() right after
it can lead to crash in HRESULT CLoopbackCapture::OnAudioSampleRequested() when application won't enter DeviceState::Capturing or DeviceState::Error state (It can be in DeviceState::Initialized or DeviceState::Starting for example))
How to reproduce:
- In Audio Mixer set output audio device to audio output of currently connected display monitor speaker.
- Launch any game in fullscreen exclusive mode (note process id of launched game) on that monitor which speakers play audio.
- Build that application https://github.com/microsoft/windows-classic-samples/tree/main/Samples/ApplicationLoopback
from cmd type "ApplicationLoopback [ProcessIdOfGame] includetree Captured.wav"
- Enter previously launched exclusive fullscreen game, wait for a while and switch back to desktop with (alt + tab). ApplicationLoopback application
should crash. Application crashes because pointer to Data pointer acquired by RETURN_IF_FAILED(m_AudioCaptureClient->GetBuffer(&Data, &FramesAvailable, &dwCaptureFlags, &u64DevicePosition, &u64QPCPosition));
in HRESULT CLoopbackCapture::OnAudioSampleRequested() becomes invalidated (There is access violation when reading that Data buffer).
I wrote that bug exists on Windows 11 22h2 beacuse I tested it on other Windows 10 and 11 opearating systems and there it works fine but it may be
connected with audio device lost on some monitors when they exit exclusive fullscreen state after pointer to Data is grabbed by m_AudioCaptureClient->GetBuffer.