From 396a2f1595b5296af9f23e115fa02090c0f43353 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 29 Dec 2013 05:58:40 -0800 Subject: Don't destroy the fluid_sfont_t if any of its samples are still playing FluidSynth apparently doesn't check for this itself before calling the free callback. --- Alc/midi/fluidsynth.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Alc/midi') diff --git a/Alc/midi/fluidsynth.c b/Alc/midi/fluidsynth.c index 697a95c8..ec4a7345 100644 --- a/Alc/midi/fluidsynth.c +++ b/Alc/midi/fluidsynth.c @@ -129,6 +129,18 @@ static void FPreset_Destruct(FPreset *self) self->NumSamples = 0; } +static ALboolean FPreset_canDelete(FPreset *self) +{ + ALsizei i; + + for(i = 0;i < self->NumSamples;i++) + { + if(fluid_sample_refcount(STATIC_CAST(fluid_sample_t, &self->Samples[i])) != 0) + return AL_FALSE; + } + return AL_TRUE; +} + static char* FPreset_getName(fluid_preset_t *preset) { return ((FPreset*)preset->data)->Name; @@ -265,6 +277,14 @@ static void FSfont_Destruct(FSfont *self) static int FSfont_free(fluid_sfont_t *sfont) { FSfont *self = STATIC_UPCAST(FSfont, fluid_sfont_t, sfont); + ALsizei i; + + for(i = 0;i < self->NumPresets;i++) + { + if(!FPreset_canDelete(&self->Presets[i])) + return 1; + } + FSfont_Destruct(self); free(self); return 0; -- cgit v1.2.3