Skip to content

Commit

Permalink
PINK: fixed some segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
voltya authored and sev- committed Jun 28, 2018
1 parent 5db9a45 commit 475f6a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
29 changes: 21 additions & 8 deletions engines/pink/objects/actions/action_play_with_sfx.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions engines/pink/objects/actions/action_play_with_sfx.h
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions engines/pink/sound.cpp
Expand Up @@ -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();
}
Expand Down

0 comments on commit 475f6a6

Please sign in to comment.