[audiere] facing random crashes with OutputStreamPtr, suspect it is not thread safe.

Started by
2 comments, last by Daaark 17 years, 1 month ago
Audiere have a garbage collection feature where it can automatically delete created variables if there is no reference to it. This prevent memory leak from occurring. But seems like this garbage collection feature is not thread safe. I suspect that for each sound effect play, a thread is created. So somehow the number use to keep track of how many variables is referencing the data sort of screw up. This cause a possibility to happen: Some audio maybe accessing the data while the data is deleted and thus this crashed the game. Anyone faced the same problem as mine? It always crash at OutputStreamPtr. Any solution? I am thinking of moving to OpenAL with boost shared_ptr. :) Any suggestion? Thanks in advance!
Advertisement
??? Could you tell us which library you're currently using? We can't tell you if a library is thread safe until we know what it is. Also, you can add wait(var), and signal(var) around the variable you think is causing the problem.
sevensevens, he mentioned 'Audiere', and that's the library in question. And I'm not sure which language you're referring to, as I'm pretty sure C/C++ doesn't have wait and signal functions as standard.
You have to do a lot of error checking in Audiere, because it doesn't do any for you. The pointers are a pain in the ass to use, as they go out of scope at the end of any function and then die out on you. So I just made all my sound pointers global in my sound.cpp file.

Here is a funciton I use to load and play my background music. Watch where I call commands on 'bgm' which is an OutputStreamPtr object. You always have to do the checks before you call anything on these, or your app will just crash right away.

Look at my big if statement, where I rotate the song. I have to check for !bgm first. If I tried to check for !bgm->isPlaying() first, the app would just shutdown write there.

//update the background music player//incrememnt songs if current BGM is done playingvoid BGMUpdate(bool rotate){    if (!IsMusicOn) return;    static int lastsong = -1;    if (!bgm || rotate || !bgm->isPlaying())    {        char cBGM[256];        int i = rand() % 6;        while (i == lastsong) i = rand() % 6;        lastsong = i;        sprintf(cBGM,"bgm/bgm_%d.mp3",i);        bgm = OpenSound(Device,cBGM,true);        if (bgm)        {            bgm->setRepeat(false);            bgm->setVolume(MusicVolume);            bgm->play();        }    }    return;}



Same here: I have an array of 2 'burn' sounds. I have to check to make sure it's valid before calling the play member function, just like above.

void SoundBurn(void){    if (!IsSoundOn) return;    int i = rand() % 2;    if (sfxBurn) sfxBurn->play();    return;}


Never call anything without checking that your sound object is valid first.

This topic is closed to new replies.

Advertisement