diff options
author | Colin Snover | 2017-11-14 11:51:08 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2017-11-18 22:35:12 +0100 |
commit | ac593e045e1410c541d2941f7fdc4cad7bcb3b5a (patch) | |
tree | b79fe2c33f33586646ac7f10bce6ae3710516d1f /engines | |
parent | 926bcb6740e19d644757fc21ccd3dbf750342985 (diff) | |
download | scummvm-rg350-ac593e045e1410c541d2941f7fdc4cad7bcb3b5a.tar.gz scummvm-rg350-ac593e045e1410c541d2941f7fdc4cad7bcb3b5a.tar.bz2 scummvm-rg350-ac593e045e1410c541d2941f7fdc4cad7bcb3b5a.zip |
FULLPIPE: Fix memory leaks in ModalVideoPlayer
Diffstat (limited to 'engines')
-rw-r--r-- | engines/fullpipe/modal.cpp | 66 | ||||
-rw-r--r-- | engines/fullpipe/modal.h | 5 |
2 files changed, 47 insertions, 24 deletions
diff --git a/engines/fullpipe/modal.cpp b/engines/fullpipe/modal.cpp index 68f04552c5..1c98f5e2df 100644 --- a/engines/fullpipe/modal.cpp +++ b/engines/fullpipe/modal.cpp @@ -34,7 +34,6 @@ #include "graphics/palette.h" #include "graphics/surface.h" -#include "video/avi_decoder.h" #include "engines/savestate.h" #include "engines/advancedDetector.h" @@ -363,30 +362,48 @@ void ModalIntroDemo::finish() { g_fp->_gameLoader->updateSystems(42); } -void ModalVideoPlayer::play(const char *filename) { - Video::AVIDecoder *aviDecoder = new Video::AVIDecoder(); +static bool checkSkipVideo(const Common::Event &event) { + switch (event.type) { + case Common::EVENT_KEYDOWN: + switch (event.kbd.keycode) { + case Common::KEYCODE_ESCAPE: + case Common::KEYCODE_RETURN: + case Common::KEYCODE_SPACE: + return true; + default: + return false; + } + case Common::EVENT_QUIT: + case Common::EVENT_RTL: + return true; + default: + return false; + } +} - if (!aviDecoder->loadFile(filename)) +void ModalVideoPlayer::play(const char *filename) { + if (!_decoder.loadFile(filename)) return; - uint16 x = (g_system->getWidth() - aviDecoder->getWidth()) / 2; - uint16 y = (g_system->getHeight() - aviDecoder->getHeight()) / 2; - bool skipVideo = false; + uint16 x = (g_system->getWidth() - _decoder.getWidth()) / 2; + uint16 y = (g_system->getHeight() - _decoder.getHeight()) / 2; - aviDecoder->start(); + _decoder.start(); - while (!g_fp->shouldQuit() && !aviDecoder->endOfVideo() && !skipVideo) { - if (aviDecoder->needsUpdate()) { - const Graphics::Surface *frame = aviDecoder->decodeNextFrame(); + while (!g_fp->shouldQuit() && !_decoder.endOfVideo()) { + if (_decoder.needsUpdate()) { + const Graphics::Surface *frame = _decoder.decodeNextFrame(); if (frame) { - Graphics::Surface *frameCopy = frame->convertTo(g_system->getScreenFormat()); - g_fp->_system->copyRectToScreen(frameCopy->getPixels(), frameCopy->pitch, - x, y, frameCopy->w, frameCopy->h); - frameCopy->free(); - delete frameCopy; + Common::ScopedPtr<Graphics::Surface, Graphics::SurfaceDeleter> tmpFrame; + if (frame->format != g_system->getScreenFormat()) { + tmpFrame.reset(frame->convertTo(g_system->getScreenFormat())); + frame = tmpFrame.get(); + } + g_fp->_system->copyRectToScreen(frame->getPixels(), frame->pitch, + x, y, frame->w, frame->h); - if (aviDecoder->hasDirtyPalette()) - g_fp->_system->getPaletteManager()->setPalette(aviDecoder->getPalette(), 0, 256); + if (_decoder.hasDirtyPalette()) + g_fp->_system->getPaletteManager()->setPalette(_decoder.getPalette(), 0, 256); g_fp->_system->updateScreen(); } @@ -394,15 +411,16 @@ void ModalVideoPlayer::play(const char *filename) { Common::Event event; while (g_fp->_system->getEventManager()->pollEvent(event)) { - if ((event.type == Common::EVENT_KEYDOWN && (event.kbd.keycode == Common::KEYCODE_ESCAPE || - event.kbd.keycode == Common::KEYCODE_RETURN || - event.kbd.keycode == Common::KEYCODE_SPACE)) - || event.type == Common::EVENT_LBUTTONUP) - skipVideo = true; + if (checkSkipVideo(event)) { + goto finish; + } } - g_fp->_system->delayMillis(aviDecoder->getTimeToNextFrame()); + g_fp->_system->delayMillis(_decoder.getTimeToNextFrame()); } + +finish: + _decoder.close(); } ModalMap::ModalMap() { diff --git a/engines/fullpipe/modal.h b/engines/fullpipe/modal.h index 6cd4581b39..5beba92eae 100644 --- a/engines/fullpipe/modal.h +++ b/engines/fullpipe/modal.h @@ -23,6 +23,8 @@ #ifndef FULLPIPE_MODAL_H #define FULLPIPE_MODAL_H +#include "video/avi_decoder.h" + namespace Fullpipe { class PictureObject; @@ -108,6 +110,9 @@ public: virtual void saveload() {} void play(const char *fname); + +private: + Video::AVIDecoder _decoder; }; class ModalMap : public BaseModalObject { |