1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Fix access to CPrologEpilogVideo after destruction from sound callback

This commit is contained in:
Ivan Savenko 2024-04-11 13:22:06 +03:00
parent c7fda0dc32
commit 9188280d02
3 changed files with 9 additions and 0 deletions

View File

@ -322,6 +322,13 @@ void CSoundHandler::setCallback(int channel, std::function<void()> function)
iter->second.push_back(function);
}
void CSoundHandler::resetCallback(int channel)
{
boost::mutex::scoped_lock lockGuard(mutexCallbacks);
callbacks.erase(channel);
}
void CSoundHandler::soundFinishedCallback(int channel)
{
boost::mutex::scoped_lock lockGuard(mutexCallbacks);

View File

@ -85,6 +85,7 @@ public:
void stopSound(int handler);
void setCallback(int channel, std::function<void()> function);
void resetCallback(int channel);
void soundFinishedCallback(int channel);
int ambientGetRange() const;

View File

@ -74,6 +74,7 @@ void CPrologEpilogVideo::show(Canvas & to)
void CPrologEpilogVideo::clickPressed(const Point & cursorPosition)
{
close();
CCS->soundh->resetCallback(voiceSoundHandle); // reset callback to avoid memory corruption since 'this' will be destroyed
CCS->soundh->stopSound(voiceSoundHandle);
CCS->soundh->stopSound(videoSoundHandle);
if(exitCb)