Windows only - I'm afraid.
If you comment out the "StopMusic" at the end, the sound will loop-stutter indefinately. (obviously) - but whether you comment that out or not, the process will still hang. (check task manager)
This below is not really how things look in my code - it's just an example that reproduces the problem. All error checking have been stripped for readability. Please note that I could very well be doing something stupidly wrong - but it doesn't feel like it.
Minimal code for DLL:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#define DLL extern "C" __declspec(dllexport)
#define SFML_STATIC
#include <SFML/Audio.hpp>
#pragma comment(lib, "sfml-audio-s.lib")
#pragma comment(lib, "sfml-system-s.lib")
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved )
{
return TRUE;
}
DLL sf::Music * PlayMusic(std::string filename)
{
sf::Music * m = new sf::Music;
m->OpenFromFile(filename);
m->Play();
return m;
}
DLL void StopMusic(sf::Music *m)
{
m->Stop();
delete m; m=0;
}
And for the executable:
#define SFML_STATIC
#include <SFML/Audio.hpp>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
// plugin stuff, platform independant usually but trimmed down here.
#define PLUGIN_LOAD(a) LoadLibraryA(a)
#define PLUGIN_GETSYM(a, b) GetProcAddress(a, b)
#define PLUGIN_UNLOAD(a) FreeLibrary(a)
#define PLUGIN_HANDLE HMODULE
#if !defined(HMODULE)
struct HINSTANCE__;
typedef struct HINSTANCE__* HMODULE;
#endif
#pragma comment(lib, "sfml-audio-s.lib")
#pragma comment(lib, "sfml-system-s.lib")
#pragma comment(lib, "sfml-main.lib")
int main()
{
// load the DLL
PLUGIN_HANDLE p = PLUGIN_LOAD("crashDLL.dll");
void * playMusic_f = PLUGIN_GETSYM(p, "PlayMusic");
void * stopMusic_f = PLUGIN_GETSYM(p, "StopMusic");
// function pointers
sf::Music *(*PlayMusic)(std::string);
void (*StopMusic)(sf::Music *);
PlayMusic = reinterpret_cast<sf::Music *(*)(std::string)>(playMusic_f);
StopMusic = reinterpret_cast<void (*)(sf::Music *)>(stopMusic_f);
// So far so good!
sf::Music * m = PlayMusic("music.ogg");
MessageBoxA(NULL, "There will be a crash in your imminent future!", "Nostradamus 2011", MB_OK);
StopMusic(m);
PLUGIN_UNLOAD(p); // crashes here, seem to be some sort of deadlock.
return EXIT_SUCCESS;
}
Put the DLL and a music file named "music.ogg" into the same directory as the executable, along with libsndfile-1.dll and openal.dll to test.