Need to fix bug with threading

DenisKoronchik

15-01-2013 15:31:48

I've found interesting bug with sound stop with OGGSOUND_THREADED.
Sound tries to delete twicely. It places into mSoundsToDestroy more then one time. I determine, that is because
when sound buffers update, they request action to stop it, and that action push into queue, without any checks if it already exists.
When process actions in void OgreOggSoundManager::_processQueuedSounds() not all of them can be perfomed, becuse limitation in 5 actions per frame.
So for example if our action to stop sound goes to queue on 6 place, then after action queue processing (limitation 5 action per frame) it still will be in action queue.
On next update of sound buffers new action to stop this sound will be added. When action queue processing, it append that sounds twicely into mSoundsToDestroy .
That cause error, when we try to delete sound twicely.

There are two ways to fix that bug: remove limitaion

void OgreOggSoundManager::_processQueuedSounds()
{
if ( !mActionsList && !mDelayedActionsList ) return;

SoundAction act;
int i=0;

// commented limit to fix bug, when
// some sounds append to actions twicely
// this is because actions not performed and
// next frame update generate new

// Perform sound requests
// Maximum 5 requests per frame
while ( /*((i++)<5) &&*/ mActionsList->pop(act) )
{
_performAction(act);
}

// If main list is empty and there are queued requests
// Start clearing them out...
//if ( i<5 )
{
// Maximum 5 requests per frame
while ( /*((i++)<5) && */mDelayedActionsList->pop(act) )
{
_performAction(act);
}
}
}


Or make flags that will be prevent second action request in:

void OgreOggISound::play(bool immediate)
{
#if OGGSOUND_THREADED
SoundAction action;
action.mSound = mName;
action.mAction = LQ_PLAY;
action.mImmediately = immediate;
action.mParams = 0;
OgreOggSoundManager::getSingletonPtr()->_requestSoundAction(action);
#else
_playImpl();
#endif
}
/*/////////////////////////////////////////////////////////////////*/
void OgreOggISound::stop(bool immediate)
{
#if OGGSOUND_THREADED
SoundAction action;
action.mSound = mName;
action.mAction = LQ_STOP;
action.mImmediately = immediate;
action.mParams = 0;
OgreOggSoundManager::getSingletonPtr()->_requestSoundAction(action);
#else
_stopImpl();
#endif
}
/*/////////////////////////////////////////////////////////////////*/
void OgreOggISound::pause(bool immediate)
{
#if OGGSOUND_THREADED
SoundAction action;
action.mSound = mName;
action.mAction = LQ_PAUSE;
action.mImmediately = immediate;
action.mParams = 0;
OgreOggSoundManager::getSingletonPtr()->_requestSoundAction(action);
#else
_pauseImpl();
#endif
}


Can't check this bug for play and pause actions, but i think it will be possible to crash.
I can made patch, but i need to know wich way to use for fixes. Thanks

stickymango

25-01-2013 13:49:50

Good catch!! :twisted:

I'll fix that now thanks.

Gdlk

13-03-2013 15:07:06

Hi!!

A question, the patch is up and ready (or it will be soon up/ready)?

I am really interested in this patch, because I think this could fix the problem in linux when the app end but no close (or sometimes made segfault when close )

Thanks!!, and btw really nice catch Denis! =)

Regards!!

stickymango

13-03-2013 21:20:23

Sorry for not posting an update, yes this should be fixed and in the latest SVN commit.