Due to SDL not allowing population of the available devices until the audio system is loaded the audio tries to set the device to a nullptr. Instead we load the default audio device and then immediately close it. This allows SDL to load correctly
This commit is contained in:
parent
51001b8806
commit
0ecc0c8bbd
|
@ -2,6 +2,7 @@
|
|||
------------------------------------------------------------------------
|
||||
- Feature: [#569] Option/cheat to disable AI companies entirely.
|
||||
- Fix: [#573] Crash caused by opening Road construction window.
|
||||
- Fix: [#588] Crash caused by changing default audio device.
|
||||
- Fix: [#595] Implementation mistake in CreateVehicle could lead to crashes.
|
||||
- Fix: [#635] Land tool not working properly, due to tool drag events not passing on coordinates.
|
||||
- Fix: [#648] Fix crash in vehicle update head caused by CreateVehicle.
|
||||
|
|
|
@ -288,6 +288,21 @@ namespace OpenLoco::Audio
|
|||
// 0x00404E53
|
||||
void initialiseDSound()
|
||||
{
|
||||
if (_devices.empty())
|
||||
{
|
||||
// If devices is empty we need to load the default audio device to initliase the audio system
|
||||
// this will then allow populating the devices
|
||||
auto& format = _outputFormat;
|
||||
format.frequency = MIX_DEFAULT_FREQUENCY;
|
||||
format.format = MIX_DEFAULT_FORMAT;
|
||||
format.channels = MIX_DEFAULT_CHANNELS;
|
||||
if (Mix_OpenAudioDevice(format.frequency, format.format, format.channels, 1024, nullptr, 0) != 0)
|
||||
{
|
||||
Console::error("Mix_OpenAudio failed: %s", Mix_GetError());
|
||||
return;
|
||||
}
|
||||
Mix_CloseAudio();
|
||||
}
|
||||
const char* deviceName = nullptr;
|
||||
const auto& cfg = Config::getNew();
|
||||
if (!cfg.audio.device.empty())
|
||||
|
@ -349,7 +364,11 @@ namespace OpenLoco::Audio
|
|||
{
|
||||
_devices.clear();
|
||||
#ifdef __HAS_DEFAULT_DEVICE__
|
||||
_devices.push_back(getDefaultDeviceName());
|
||||
auto defaultDevice = getDefaultDeviceName();
|
||||
if (defaultDevice != nullptr)
|
||||
{
|
||||
_devices.push_back(getDefaultDeviceName());
|
||||
}
|
||||
#endif
|
||||
auto count = SDL_GetNumAudioDevices(0);
|
||||
for (auto i = 0; i < count; i++)
|
||||
|
|
Loading…
Reference in New Issue