diff options
author | whiterandrek | 2018-03-30 13:52:58 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | 475f6a62bdaa058cff6371989004291fcec9feb1 (patch) | |
tree | 1d980c69a6e7ff434c7800f21e265b1d24a20eab | |
parent | 5db9a454581ff9b3f5e8160e401c0c741f321e9c (diff) | |
download | scummvm-rg350-475f6a62bdaa058cff6371989004291fcec9feb1.tar.gz scummvm-rg350-475f6a62bdaa058cff6371989004291fcec9feb1.tar.bz2 scummvm-rg350-475f6a62bdaa058cff6371989004291fcec9feb1.zip |
PINK: fixed some segfaults
-rw-r--r-- | engines/pink/objects/actions/action_play_with_sfx.cpp | 29 | ||||
-rw-r--r-- | engines/pink/objects/actions/action_play_with_sfx.h | 2 | ||||
-rw-r--r-- | engines/pink/sound.cpp | 4 |
3 files changed, 25 insertions, 10 deletions
diff --git a/engines/pink/objects/actions/action_play_with_sfx.cpp b/engines/pink/objects/actions/action_play_with_sfx.cpp index 8c41176cdb..8c8cf6fa9d 100644 --- a/engines/pink/objects/actions/action_play_with_sfx.cpp +++ b/engines/pink/objects/actions/action_play_with_sfx.cpp @@ -28,12 +28,12 @@ namespace Pink { -void Pink::ActionPlayWithSfx::deserialize(Pink::Archive &archive) { +void ActionPlayWithSfx::deserialize(Pink::Archive &archive) { ActionPlay::deserialize(archive); archive >> _isLoop >> _sfxArray; } -void Pink::ActionPlayWithSfx::toConsole() { +void ActionPlayWithSfx::toConsole() { debug("\tActionPlayWithSfx: _name = %s, _fileName = %s, z = %u, _startFrame = %u," " _endFrame = %u, _isLoop = %u", _name.c_str(), _fileName.c_str(), _z, _startFrame, _stopFrame); for (int i = 0; i < _sfxArray.size(); ++i) { @@ -68,36 +68,49 @@ void ActionPlayWithSfx::updateSound() { } ActionPlayWithSfx::~ActionPlayWithSfx() { - end(); + for (int i = 0; i < _sfxArray.size(); ++i) { + delete _sfxArray[i]; + } } void ActionPlayWithSfx::end() { ActionPlay::end(); for (int i = 0; i < _sfxArray.size(); ++i) { - delete _sfxArray[i]; + _sfxArray[i]->end(); } } -void Pink::ActionSfx::deserialize(Pink::Archive &archive) { +void ActionSfx::deserialize(Pink::Archive &archive) { archive >> _frame >> _volume >> _sfxName; archive.readObject(); } -void Pink::ActionSfx::toConsole() { +void ActionSfx::toConsole() { debug("\t\tActionSfx: _sfx = %s, _volume = %u, _frame = %u", _sfxName.c_str(), _volume, _frame); } void ActionSfx::play(GamePage *page) { - _sound = page->loadSound(_sfxName); + if (!_sound) + _sound = page->loadSound(_sfxName); + _sound->play(Audio::Mixer::SoundType::kSFXSoundType, _volume, 0); } ActionSfx::~ActionSfx() { - delete _sound; + end(); } uint32 ActionSfx::getFrame() { return _frame; } +ActionSfx::ActionSfx() + : _sound(nullptr) +{} + +void ActionSfx::end() { + delete _sound; + _sound = nullptr; +} + } // End of namespace Pink
\ No newline at end of file diff --git a/engines/pink/objects/actions/action_play_with_sfx.h b/engines/pink/objects/actions/action_play_with_sfx.h index 7e4448abbb..020b380a58 100644 --- a/engines/pink/objects/actions/action_play_with_sfx.h +++ b/engines/pink/objects/actions/action_play_with_sfx.h @@ -53,12 +53,14 @@ class GamePage; class ActionSfx : public Object { public: + ActionSfx(); virtual ~ActionSfx(); virtual void deserialize(Archive &archive); virtual void toConsole(); void play(GamePage *page); uint32 getFrame(); + void end(); private: Sound *_sound; diff --git a/engines/pink/sound.cpp b/engines/pink/sound.cpp index 5312c965c9..73899a3438 100644 --- a/engines/pink/sound.cpp +++ b/engines/pink/sound.cpp @@ -64,14 +64,14 @@ void Sound::play(Audio::Mixer::SoundType type, int volume, bool isLoop) { _stream = Audio::makeLoopingAudioStream(seekableStream, 0, 0, 0); } - _mixer->playStream(type, &_handle ,_stream); + _mixer->playStream(type, &_handle ,_stream, -1 , Audio::Mixer::kMaxChannelVolume, 0,DisposeAfterUse::NO); } bool Sound::load(Common::SeekableReadStream *stream) { // Vox files in pink have wave format. // RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 22050 Hz - _stream = Audio::makeWAVStream(stream, DisposeAfterUse::NO); + _stream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); return isLoaded(); } |