brummer10 / Fluida.lv2

Fluidsynth as LV2 plugin
GNU General Public License v2.0
33 stars 4 forks source link

Invalid channel list causing crash with some .sf2s. #30

Closed Stazed closed 7 months ago

Stazed commented 7 months ago

With some sf2 files (maybe broken?) the call to : XSynth.cpp

Line 242 : int XSynth::get_instrument_for_channel(int channel)

will return -1 on:

Line 246: if (!preset) return -1;

On the host non-mixer-xt (I am the developer), the lv2 file is saved in .ttl format with lilv_state_save(). The -1 value gets saved in the channel_list - Example:

 <https://github.com/brummer10/Fluida.lv2#channel_list> [
            a atom:Vector ;
            atom:childType atom:Int ;
            rdf:value (
                "0"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
                "-1"^^xsd:int
            )
        ]

When attempting to restore the plugin state, the -1 channel value causes Fluida.lv2 to crash with a:

terminate called after throwing an instance of 'std::length_error' what(): basic_string::_M_create

or some other similar related error.

I patched with:

-- if (!preset) return -1; ++ if (!preset) return 0;

Which changed the -1 channel_list saving to 0 and stopped the plugin from crashing on re-load, with no side effects that I could determine.

I also noticed that the calls to XSynth::get_instrument_for_channel() do not handle the -1 error in any case. I'm not sure what the best solution is for the error conditions, but returning 0 seemed to work if no preset was found.

Anyhow you may know of a better solution...

Thanks.

brummer10 commented 7 months ago

Hi Yes, indeed we didn't need the -1 return from get_instrument_for_channel in Fluida. So I followed your suggestion and make it return 0 on error. In our context that doesn't matter.
Thanks for the hint, should be fixed with the latest commit.

Stazed commented 7 months ago

Great! Now all my old custom (somewhat suspect) .sf2s work without issue. Thanks again for this beautiful plugin...