Sign in to follow this  
lXciD

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

Recommended Posts

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!

Share this post


Link to post
Share on other sites
??? 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 playing
void 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[i]) sfxBurn[i]->play();
return;
}


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this