the small example program below is giving me an assertion error (‘settings != NULL’ failed) and I can’t understand why it thinks the settings structure pointer is NULL.
File test.c:
#include <fluidsynth.h>
int main(int argc, char** argv)
{
fluid_settings_t* settings = new_fluid_settings();
fluid_synth_setint(settings, "synth.polyphony", 128); //assertion error
delete_fluid_settings(settings);
return 0;
}
Compiled with: gcc test.c -lfluidsynth.
I’ve tried printing the address returned by new_fluid_settings() but it seems a valid address to me.
So I’ve searched through the fluidsynth 1.1.5 source code and find out the line 1213 of the file utils/fluid_settings.c :
fluid_return_val_if_fail (settings != NULL, 0);
But fluid_return_val_if_fail is just a simple macro for calling GLib’s g_return_val_if_fail (utils/fluid_sys.h:59).
Since the settings address is a valid one, I can’t think of something else. Isn’t it true that NULL pointers point to the address 0x00?
Am I forgetting something important ?
Print the address before using it, using e.g.
printf("the settings are at %p\n", settings);; and you can of course also add protection yourself:If it’s the _new() call that is failing, you need to dig into why that could happen, of course.
It used to be that you had to manually initialize the glib library that FluidSynth seems to depend on, but that should no longer be necessary.
I had a brief look, and it seems it tries to initialize a mutex inside the settings object (to make it thread-safe, I assume), so it’s possible that you need to add a call to
g_thread_init()to yourmain(), before the call tonew_fluid_settings().