1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-10 06:52:05 +01:00

Fix #14889: [FluidSynth] Don't try to load a soundfont that doesn't exist.

This commit is contained in:
Peter Nelson
2025-12-08 21:46:36 +00:00
committed by Peter Nelson
parent 2162983054
commit 9695de9e1c

View File

@@ -11,6 +11,7 @@
#include "fluidsynth.h" #include "fluidsynth.h"
#include <filesystem>
#include <fluidsynth.h> #include <fluidsynth.h>
#include <mutex> #include <mutex>
@@ -31,7 +32,7 @@ static struct {
static FMusicDriver_FluidSynth iFMusicDriver_FluidSynth; static FMusicDriver_FluidSynth iFMusicDriver_FluidSynth;
/** List of sound fonts to try by default. */ /** List of sound fonts to try by default. */
static const char *default_sf[] = { static const char *_default_soundfonts[] = {
/* FluidSynth preferred */ /* FluidSynth preferred */
/* See: https://www.fluidsynth.org/api/settings_synth.html#settings_synth_default-soundfont */ /* See: https://www.fluidsynth.org/api/settings_synth.html#settings_synth_default-soundfont */
"/usr/share/soundfonts/default.sf2", "/usr/share/soundfonts/default.sf2",
@@ -49,8 +50,6 @@ static const char *default_sf[] = {
/* Debian/Ubuntu/OpenSUSE alternatives */ /* Debian/Ubuntu/OpenSUSE alternatives */
"/usr/share/sounds/sf2/TimGM6mb.sf2", "/usr/share/sounds/sf2/TimGM6mb.sf2",
"/usr/share/sounds/sf2/FluidR3_GS.sf2", "/usr/share/sounds/sf2/FluidR3_GS.sf2",
nullptr
}; };
static void RenderMusicStream(int16_t *buffer, size_t samples) static void RenderMusicStream(int16_t *buffer, size_t samples)
@@ -99,9 +98,9 @@ std::optional<std::string_view> MusicDriver_FluidSynth::Start(const StringList &
/* If no default soundfont found, try our own list. */ /* If no default soundfont found, try our own list. */
if (sfont_id == FLUID_FAILED) { if (sfont_id == FLUID_FAILED) {
for (int i = 0; default_sf[i]; i++) { for (const char *soundfont : _default_soundfonts) {
if (!fluid_is_soundfont(default_sf[i])) continue; if (!std::filesystem::exists(soundfont) || !fluid_is_soundfont(soundfont)) continue;
sfont_id = fluid_synth_sfload(_midi.synth, default_sf[i], 1); sfont_id = fluid_synth_sfload(_midi.synth, soundfont, 1);
if (sfont_id != FLUID_FAILED) break; if (sfont_id != FLUID_FAILED) break;
} }
} }