If I call this function directly from the main program, it’s works.
But, if I call this function in a separate thread like:
thread1 = SDL_CreateThread (Play_Sound, NULL);
I have the error (from the function):
Mix_LoadWAV:-Mix_LoadWAV_RW with NULL src
I am trying to play sound and the function must be called from a separate thread.
For what it’s worth, SDL_mixer does all its heavy processing in a
seperate thread already, so you don’t need to spin a thread to keep the
audio seperate. Unless there’s another reason to keep a seperate thread,
just call Mix_LoadWAV and Mix_PlayChannel from the main thread.
I don’t see any reason your code wouldn’t work, though, unless fopen()
is failing from another thread (Mix_LoadWav() eventually calls fopen(),
and would give that error message if it fails). If it’s a C runtime
conflict (which has been known to happen on Windows), you can load the
file into memory yourself and use a memory rwops to feed it to SDL_mixer.