[Resolved] stop()ing and play()ing a sound many times

liquidllama

04-04-2008 06:07:29

I have a menu sound effect, for example for a button click. In order to restart the sound, whenever a button is clicked I use the following code:
m_pClickSound->stop();
m_pClickSound->play();


After many clicks (maybe 100 or more, but seemingly a random number), I get an exception:

"OGRE EXCEPTION(40964:): Failed to unqueue Buffers: OpenAL Error: There is no current context in OgreAL::Sound::unqueueBuffers"

and the application exits, with no useable call stack. I am using the threaded version of OgreAL, updated earlier today, but the last revision of SVN was almost a month ago. This happens with .ogg and .wav files, and have tried it with a few different sounds...sometimes I get the same results, sometimes after about the same number of plays all of my sound effects will refuse to play. Is there any reason why it would work fine for so many repetitions and then just die? The sound is not streaming, because it is very short, and I don't want it to loop. Should I be using another method to play a single sound over and over again?

Thanks!

stickymango

04-04-2008 21:40:58

I can confirm I get this same error too, although its usually quicker then a 100 repetitions...

liquidllama

09-04-2008 06:40:20

More info:

As a test, I ran an app that watched for the sound to finish, and then ->stop()ed and ->play()ed it again while a key is held down (maybe similar to a footstep scenario, where the designer wants to allow the sound to finish even if the user lets off of the key, but where looping would be inappropriate), and it crashes after EXACTLY 100 plays (multiple trials). I also logged the number of available sources in the Ogre log, and (coincidentally?) on my X-Fi OgreAL allocates exactly 100 sources. I've started digging into the source, but haven't found anything yet. Would there be any reason that the SoundManager would not allocate a source to a sound that it has previously held? That is the only thing I can find that might be causing this scenario.

liquidllama

09-04-2008 07:23:30

Another update:

I had two friends run the code on their machines with no problems after 300+ plays, and so went and downloaded updated drivers for my X-Fi.

Problem solved. Just leaving this note for anyone else who might run into this problem!

stickymango

09-04-2008 15:08:45

Are you saying that new drivers solved your problem? That wouldn't help me :cry:

Gohla

09-04-2008 17:10:18

I'm also getting this error.
17:57:17: OGRE EXCEPTION(40964:): Failed to unqueue Buffers: OpenAL Error: There is no current context in OgreAL::Sound::unqueueBuffers

I also have a X-Fi card (X-Fi XtremeGamer) so after your post I updated my drivers to see if that solved anything. After updating the drivers the bug didn't occur as much as it did before the update but it still happens a lot (~70% of the time).
A friend of mine has the same soundcard as me so I asked him to update his drivers and run my app and he got more or less the same results.

I'm using OgreAL together with NxOgre's test application Cake, here's a piece of code that plays some sounds when the user spawns something:

if (mKeyboard->isKeyDown(KC_4)) {
soundManager->getSound("Spawn")->play();

for(int i=0; i<100; i++) {
Vector3 place = Vector3(NxMath::rand(-10,10),NxMath::rand(-10,10),NxMath::rand(-10,10));

mScene->createBody("Franky; cube.1m.mesh", new Cube(1), place, ActorParams("mass: 10"));

nbActors++;
}
}

Either my application doesn't crash or it always crashes after 3 sounds have been played.

There are also some looping sounds that play when a button is pressed and stopped when it is released, but these don't seem to crash the app.

I hope someone can do something about this bug, I really want to use OgreAL because it's so easy to integrate but it is unusable with this bug :(

Gohla

10-04-2008 12:17:30

Changed my code to:

if(soundManager->hasSound("Spawn")) {
soundManager->destroySound("Spawn");
}
OgreAL::Sound* spawnSound = soundManager->createSound("Spawn", "spawn.ogg");
spawnSound->setRelativeToListener(true);
spawnSound->play();


Seems to fix it, no more crashes, but it's not very efficient :P

stickymango

24-04-2008 14:57:12

Think I've solved the OP problem with this code modification to Sound::Play(): if(!mBuffersQueued)
{
// Unqueue any buffers that may be left over
unqueueBuffers();
queueBuffers();
}
and change it to this: if(!mBuffersQueued)
{
// queue any buffers
queueBuffers();
}
else
{
// Unqueue any buffers that may be left over
unqueueBuffers();
queueBuffers();
}
It seems to work fine for me...