Plugins development: how to call SDL_Quit

I used SDL2 for implementing an audio driver for FluidSynth:

it works fine but a problem about calling SDL_Quit may happen.
Actually, I don not know if the main program using FluidSynth is also using SDL2. Calling SDL_Quit() cleans up everything and this could be a problem if a program is also using SDL2 for other tasks. But I have to call it in case of the main program is not using SDL2 at all. At the moment I have not found a solution for this problem, which should be a common issue for all applications using SDL2 for implementing a plugin.
It is also not recommended to use atexit() because the drawbacks also explained in your documentation.
Searching the network/forums/mailing lists did not give a response to this problem.

Have you some suggestions for this trouble?


I might be completely off the track here, but I think a good strategy for any library would be to carefully use SDL_InitSubSystem and SDL_QuitSubSystem to manage its own initialization needs and then when done with everything use SDL_WasInit to check if there are any other initializations. If not then it is safe to call SDL_Quit, otherwise you leave it to the application.

In your particular case I guess it might look like something like this:

if(SDL_WasInit(0) == 0)

I’ve never really tried this, but it’s my best guess reading the docs.

You should never use SDL_Quit() in a plugin. As namark suggested, use SDL_InitSubSystem() and SDL_QuitSubSystem() instead.