Bug #620 Fixed crash when no audio devices are present (#118)

This commit is contained in:
Krystian Booker 2022-08-30 08:10:05 -04:00 committed by GitHub
parent 2d42c885da
commit 60074c440d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -226,6 +226,11 @@ std::vector<DirectSoundAPI::DeviceDescriptionPtr> DirectSoundAPI::GetDevices()
return TRUE;
}, &result);
//Exclude default primary sound device if no other sound devices are available
if (result.size() == 1 && result.at(0).get()->GetIdentifier() == L"default") {
result.clear();
}
return result;
}

View File

@ -187,10 +187,6 @@ const std::vector<XAudio2API::DeviceDescriptionPtr>& XAudio2API::RefreshDevices(
// this function must be called from the same thread as we called CoInitializeEx
s_devices.clear();
// always add the default device
auto default_device = std::make_shared<XAudio2DeviceDescription>(L"Primary Sound Driver", L"");
s_devices.emplace_back(default_device);
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE)))
return s_devices;
@ -262,6 +258,12 @@ const std::vector<XAudio2API::DeviceDescriptionPtr>& XAudio2API::RefreshDevices(
}
}
// Only add default device if audio devices exist
if (s_devices.size() > 0) {
auto default_device = std::make_shared<XAudio2DeviceDescription>(L"Primary Sound Driver", L"");
s_devices.insert(s_devices.begin(), default_device);
}
wbem_enum->Release();
// Clean up