std::vector debug assertation failed

pra

12-03-2008 20:11:22

i alerady posted this error:

now I got it again, and now it is for some reason debuggable.

here is the call stack:
OgreAL_d.dll!std::_Vector_const_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> >::operator--() Line 133 + 0x3e bytes C++
OgreAL_d.dll!std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> >::operator--() Line 350 C++
OgreAL_d.dll!std::_Insertion_sort<std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> >,OgreAL::SoundManager::SortLowToHigh>(std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> > _First=0x0855c5f8 {mDerivedPosition={...} mDerivedDirection={...} mLastParentOrientation={...} ...}, std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> > _Last=0xfdfdfdfd {mDerivedPosition={...} mDerivedDirection={...} mLastParentOrientation={...} ...}, OgreAL::SoundManager::SortLowToHigh _Pred={...}) Line 3131 + 0x12 bytes C++
OgreAL_d.dll!std::_Sort<std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> >,int,OgreAL::SoundManager::SortLowToHigh>(std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> > _First=0x0855c5f8 {mDerivedPosition={...} mDerivedDirection={...} mLastParentOrientation={...} ...}, std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> > _Last=0xfdfdfdfd {mDerivedPosition={...} mDerivedDirection={...} mLastParentOrientation={...} ...}, int _Ideal=3, OgreAL::SoundManager::SortLowToHigh _Pred={...}) Line 3252 + 0x51 bytes C++
OgreAL_d.dll!std::sort<std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> >,OgreAL::SoundManager::SortLowToHigh>(std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> > _First=0x0855c5f8 {mDerivedPosition={...} mDerivedDirection={...} mLastParentOrientation={...} ...}, std::_Vector_iterator<OgreAL::Sound *,std::allocator<OgreAL::Sound *> > _Last=0xfdfdfdfd {mDerivedPosition={...} mDerivedDirection={...} mLastParentOrientation={...} ...}, OgreAL::SoundManager::SortLowToHigh _Pred={...}) Line 3261 + 0x66 bytes C++
> OgreAL_d.dll!OgreAL::SoundManager::updateSounds() Line 815 + 0x6e bytes C++
OgreAL_d.dll!OgreAL::SoundManager::frameStarted(const Ogre::FrameEvent & evt={...}) Line 401 C++


i'm not really able to understand all the stl stuff... the last line of OgreAL code is
std::sort(mActiveSounds.begin(), mActiveSounds.end(), SortLowToHigh());
in SoundManager::UpdateSounds()

i haven't done anything special, it seems to occur randomly. maybe fast creation and destruction of sounds affects the probability of this error...

CaseyB

12-03-2008 20:29:06

std::sort(mActiveSounds.begin(), mActiveSounds.end(), SortLowToHigh());

This just sorts the sounds so they are in order from lowest priority to highest. You can put print statements in the SortLowToHigh struct and see where it's failing. If you can tell me that it would be a great help in figuring out what's going wrong since I can't recreate the issue.

pra

12-03-2008 21:17:25

i'll try, but it is not easy to reproduce it... as i said, it occurs randomly and is quite rare...

CaseyB

12-03-2008 22:54:30

Yeah, that's that bad part! But if you put the prints in there you can see what's going on when it does. You can just log when things happen and when it crashes you can note when it quits. :? Kind of a crappy what to do it, but I can't think of anything else!

pra

14-03-2008 02:16:23

ok. i asked some guy who has more C++ skill with me, and together we found a possible reason: it is if a sound stops while they are being sorted in SoundManager::updateSounds().
I could provoke the error by adding
SleepEx(10, true)
to
bool SortLowToHigh::operator()(const Sound *sound1, const Sound *sound2)const
(it does not make the error appear, but seems to raise the probability, at least for me)

that might explain why I am the only one who has ever seen it: i have a pretty slow laptop here, it is in debug mode, and VC++ is opened at the same time, too. Usually also Firefox...

CaseyB

14-03-2008 03:11:49

it is if a sound stops while they are being sorted in SoundManager::updateSounds().
You could absolutely be correct! If a sound stops in the middle of being sorted that changes its relation to the other sounds and causes the return from the sort to be inconsistent! This would also be why it only happens with threading enabled!! I am going to make a fix. Hold on.

pra

26-03-2008 16:12:13

i hadn't internet access for some time and can't use tortoisesvn from this PC... is the update alerady there? if yes, what files do i need to download?

stickymango

26-03-2008 16:51:42

Could this also be the cause of my crash when stopping audio? I'm using threading and getting random crashes when stopping sounds... Has a fix been committed yet?

pra

07-04-2008 21:02:39

any progress yet? it still occurs from time to time :(

manowar

18-06-2008 10:29:26

I am having exactly the same problem. Caseyb is not around anymore. Any news from him ? This is a really cool wrapper, but we cannot really use it because of some random crashes. I have been trying to fix some of them for the last few days but it is not something easy....especially threading issues. How to fix that and make sure that we can't stop a sound while sorting. I thought OGREAL_LOCK_AUTO_MUTEX in updateSounds() was there for that reason.
Any help is welcome.

pra

18-06-2008 12:50:42

I decided that it is easier to implement OpenAL by myself than to fix this bug. At least for me, i'm not really skilled with threading. The most difficult part is to load OGGs, but the positioning and the rest is pretty easy.

Maybe I should clean my implementation up a little and release the code

manowar

18-06-2008 13:16:16

Thanks pra, but what about streaming sound ? Are you using them ? If yes, how do you update them ?Using a FrameListener ?

pra

18-06-2008 23:53:05

oh. absolutely forgot about that. no, i'm not using them, and i have no idea how they work...

makiolo

29-09-2011 19:35:36

It fix bug for me:


struct SoundManager::SortLowToHigh
{
bool operator()(const Sound *sound1, const Sound *sound2) const
{
// First we see if either sound has stopped and not given up its source
if(sound1->isStopped() && !sound2->isStopped())
return true;
else if(sound2->isStopped() && !sound1->isStopped())
return false;
else if(sound1->isStopped() && sound2->isStopped())
return sound1 < sound2;

// If they are both playing we'll test priority
if(sound1->getPriority() < sound2->getPriority())
return true;
else if (sound1->getPriority() > sound2->getPriority())
return false;

// If they are the same priority we'll test against the
// distance from the listener
Ogre::Real distSound1, distSound2;

Listener* listener = Listener::getSingletonPtr();

if(listener)
{
Ogre::Vector3 listenerPos = listener->getDerivedPosition();

if(sound1->isRelativeToListener())
{
distSound1 = sound1->getPosition().squaredLength();
}
else
{
distSound1 = sound1->getDerivedPosition().squaredDistance(listenerPos);
}

if(sound2->isRelativeToListener())
{
// BUG ?
//distSound2 = sound1->getPosition().length();
distSound2 = sound2->getPosition().squaredLength();
}
else
{
distSound2 = sound2->getDerivedPosition().squaredDistance(listenerPos);
}

}
else
{
distSound1 = sound1->getPosition().squaredLength();
distSound2 = sound2->getPosition().squaredLength();
}

if(distSound1 > distSound2)
return true;
else if(distSound1 < distSound2)
return false;

// If they are at the same priority and distance from the listener then
// they are both equally well suited to being sacrificed so we compare
// their pointers since it really doesn't matter
return sound1 < sound2;
}
};