audiotraits: Fix crash when encountering corruption in OpenAL stream

Partial backport of #1452
This commit is contained in:
rdb 2023-02-03 14:44:14 +01:00
parent a20996d2aa
commit 718bac1c69

View File

@ -968,23 +968,22 @@ update() {
SoundsPlaying sounds_finished; SoundsPlaying sounds_finished;
double rtc = TrueClock::get_global_ptr()->get_short_time(); double rtc = TrueClock::get_global_ptr()->get_short_time();
SoundsPlaying::iterator i=_sounds_playing.begin(); SoundsPlaying::iterator it = _sounds_playing.begin();
for (; i!=_sounds_playing.end(); ++i) { while (it != _sounds_playing.end()) {
OpenALAudioSound *sound = (*i); PT(OpenALAudioSound) sound = *(it++);
sound->pull_used_buffers(); sound->pull_used_buffers();
sound->push_fresh_buffers(); sound->push_fresh_buffers();
sound->restart_stalled_audio(); sound->restart_stalled_audio();
sound->cache_time(rtc); sound->cache_time(rtc);
if ((sound->_source == 0)|| if (sound->_source == 0 ||
((sound->_stream_queued.size() == 0)&& (sound->_stream_queued.empty() &&
(sound->_loops_completed >= sound->_playing_loops))) { (sound->_loops_completed >= sound->_playing_loops))) {
sounds_finished.insert(*i); sounds_finished.insert(std::move(sound));
} }
} }
i=sounds_finished.begin(); for (OpenALAudioSound *sound : sounds_finished) {
for (; i!=sounds_finished.end(); ++i) { sound->finished();
(**i).finished();
} }
} }