[Scummvm-git-logs] scummvm master -> 0dd0e487e9b5fde70fb34732524d65ad1b490513
fracturehill
noreply at scummvm.org
Sun Jul 21 19:10:16 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
0dd0e487e9 NANCY: Fix memory leak in SoundManager
Commit: 0dd0e487e9b5fde70fb34732524d65ad1b490513
https://github.com/scummvm/scummvm/commit/0dd0e487e9b5fde70fb34732524d65ad1b490513
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2024-07-21T21:10:01+02:00
Commit Message:
NANCY: Fix memory leak in SoundManager
The LoopingAudioStream object that was being created
on the spot and passed to the Mixer when calling playSound was not being tracked anywhere, and was
getting leaked (though the underlying stream was
properly deleted). This commit adds a pointer to that
(maybe) looped stream and makes sure the underlying
data is getting deleted through it.
Changed paths:
engines/nancy/sound.cpp
engines/nancy/sound.h
diff --git a/engines/nancy/sound.cpp b/engines/nancy/sound.cpp
index 01478486113..a0e0e89e79a 100644
--- a/engines/nancy/sound.cpp
+++ b/engines/nancy/sound.cpp
@@ -289,8 +289,9 @@ void SoundManager::loadSound(const SoundDescription &description, SoundEffectDes
Channel &chan = _channels[description.channelID];
- delete chan.stream;
+ delete chan.streamForMixer;
chan.stream = nullptr;
+ chan.streamForMixer = nullptr;
chan.name = description.name;
chan.playCommands = description.playCommands;
@@ -309,7 +310,8 @@ void SoundManager::loadSound(const SoundDescription &description, SoundEffectDes
Common::Path path(description.name + (g_nancy->getGameType() == kGameTypeVampire ? ".dwd" : ".his"));
Common::SeekableReadStream *file = SearchMan.createReadStreamForMember(path);
if (file) {
- _channels[description.channelID].stream = makeHISStream(file, DisposeAfterUse::YES, description.samplesPerSec);
+ chan.stream = makeHISStream(file, DisposeAfterUse::YES, description.samplesPerSec);
+ chan.streamForMixer = Audio::makeLoopingAudioStream(chan.stream, chan.numLoops);
}
}
@@ -383,7 +385,7 @@ void SoundManager::playSound(uint16 channelID) {
_mixer->playStream( chan.type,
&chan.handle,
- Audio::makeLoopingAudioStream(chan.stream, numLoops),
+ chan.streamForMixer,
channelID,
(int)chan.volume * 255 / 100,
0, DisposeAfterUse::NO);
@@ -467,8 +469,9 @@ void SoundManager::stopSound(uint16 channelID) {
// Persistent sounds only stop playing but do not get unloaded
if (!chan.isPersistent) {
chan.name = Common::String();
- delete chan.stream;
+ delete chan.streamForMixer;
chan.stream = nullptr;
+ chan.streamForMixer = nullptr;
delete chan.effectData;
chan.effectData = nullptr;
chan.position.set(0, 0, 0);
@@ -687,7 +690,7 @@ void SoundManager::initSoundChannels() {
}
SoundManager::Channel::~Channel() {
- delete stream;
+ delete streamForMixer;
delete effectData;
}
diff --git a/engines/nancy/sound.h b/engines/nancy/sound.h
index 1121b593a4c..68bb1c6bc7f 100644
--- a/engines/nancy/sound.h
+++ b/engines/nancy/sound.h
@@ -131,6 +131,7 @@ protected:
uint16 panAnchorFrame = 0;
bool isPanning = false;
Audio::SeekableAudioStream *stream = nullptr;
+ Audio::AudioStream *streamForMixer = nullptr;
Audio::SoundHandle handle;
bool isPersistent = false;
More information about the Scummvm-git-logs
mailing list