scanmaster_k
07-02-2008 18:18:28
Hi, when I set and event handler for a finnished song and the song finnishes I get an assertion saying map/set iterator is not incrementable. If I don't set such an handler my little music box works fine.
Any clues?
Scanmaster_K
CaseyB
07-02-2008 19:21:52
I'll take a look at it tonight! Thanks for reporting!
CaseyB
13-02-2008 01:43:59
I can't make it crash, I did make a change that fixed a bug where the handlers weren't being called reliably, but I don't think that would have caused the crash. What are you doing in the handler? If you can post the code here I'll do my best to recreate your situation as precisely as I can.
scanmaster_k
13-02-2008 08:29:15
Hi
This is my callback function
void SoundUtilities::onSongEnd(OgreAL::Sound *song)
{
startPlay();
}
It goes here
void SoundUtilities::startPlay(void)
{
if(_songs.empty() == false) {
Ogre::String file;
if(_shuffle == false) {
_currentIndex++;
} else {
_currentIndex = static_cast<size_t>(Ogre::Math::RangeRandom(0.0, (_songs.size() - 1)));
}
if(_currentIndex >= _songs.size()) {
_currentIndex = 0;
} else if(_currentIndex <= 0) {
_currentIndex = (_songs.size() - 1);
}
file = _songs.at(_currentIndex);
if(_currentSong != NULL) {
_currentSong->stop();
OgreAL::SoundManager::getSingletonPtr()->destroySound(_currentSong);
}
_currentSong = OgreAL::SoundManager::getSingletonPtr()->createSound(file, file, false, true);
if(_currentSong != NULL) {
_currentSong->setGain(_musicVolume);
// Fix: Causes assertion when song is finished.
//_currentSong->addSoundFinishedHandler(_instance, &SoundUtilities::onSongEnd);
_currentSong->play();
}
}
}
When I controll the songs using next, stop, play / pause and so on I don't get any errors.
Edit: _currentSong->play() returns false, but ->isPlaying() returns true.
Thanks
Scanmaster_K
CaseyB
13-02-2008 15:16:56
Thanks! I'll have a look at this tonight!
Elenssar
07-04-2008 18:44:38
I think may be the problem is in the function:
bool Sound::updateSound() {
...
if(isStopped() && !mManualStop && mFinishedCallback) {
//This is the call to onfinished handler
mFinishedCallback->execute(this);
}
//the function continues, asuming the sound exists.
...
}
When it calls the "onfinished" handler, it not returns, so if you delete the sound in the call, it will crash trying to use the resources of the sound after the call in the updateSound function.
I added a "return true;" after the call. Till now for me works, but I don't know if this brings other problems.