diff options
author | Willem Jan Palenstijn | 2015-12-26 21:59:10 +0100 |
---|---|---|
committer | Willem Jan Palenstijn | 2015-12-26 21:59:10 +0100 |
commit | 90ac7a2bcb620eb29194eb94458f45d48e794c59 (patch) | |
tree | 4e428ac394bed5b1ca1a9de925e88bc82772f5d6 /engines | |
parent | e4027040a807f3dee5c902d03971162498c636fe (diff) | |
download | scummvm-rg350-90ac7a2bcb620eb29194eb94458f45d48e794c59.tar.gz scummvm-rg350-90ac7a2bcb620eb29194eb94458f45d48e794c59.tar.bz2 scummvm-rg350-90ac7a2bcb620eb29194eb94458f45d48e794c59.zip |
LAB: Clean up Image._imageData memory handling
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/dispman.cpp | 19 | ||||
-rw-r--r-- | engines/lab/image.cpp | 11 | ||||
-rw-r--r-- | engines/lab/image.h | 9 | ||||
-rw-r--r-- | engines/lab/special.cpp | 8 | ||||
-rw-r--r-- | engines/lab/tilepuzzle.cpp | 7 |
5 files changed, 28 insertions, 26 deletions
diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp index fb25472b3d..a332a57e7d 100644 --- a/engines/lab/dispman.cpp +++ b/engines/lab/dispman.cpp @@ -782,12 +782,12 @@ void DisplayMan::doTransWipe(const Common::String filename) { Image imgSource(_vm); imgSource._width = _screenWidth; imgSource._height = lastY; - imgSource._imageData = bitMapBuffer; + imgSource.setData(bitMapBuffer, true); Image imgDest(_vm); imgDest._width = _screenWidth; imgDest._height = _screenHeight; - imgDest._imageData = getCurrentDrawingBuffer(); + imgDest.setData(getCurrentDrawingBuffer(), false); for (int j = 0; j < 2; j++) { for (int i = 0; i < 2; i++) { @@ -800,7 +800,7 @@ void DisplayMan::doTransWipe(const Common::String filename) { linesDone = 0; } - imgDest._imageData = getCurrentDrawingBuffer(); + imgDest.setData(getCurrentDrawingBuffer(), false); if (j == 0) { imgSource.blitBitmap(0, curY, &imgDest, 0, curY, _screenWidth, 2, false); @@ -815,9 +815,6 @@ void DisplayMan::doTransWipe(const Common::String filename) { } // for i } // for j - // Prevent the Image destructor from deleting the drawing buffer - imgDest._imageData = nullptr; - // bitMapBuffer will be deleted by the Image destructor } @@ -872,7 +869,7 @@ void DisplayMan::blackAllScreen() { void DisplayMan::scrollDisplayX(int16 dx, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer) { Image img(_vm); - img._imageData = buffer; + img.setData(buffer, false); if (x1 > x2) SWAP<uint16>(x1, x2); @@ -897,14 +894,11 @@ void DisplayMan::scrollDisplayX(int16 dx, uint16 x1, uint16 y1, uint16 x2, uint1 rectFill(x2 + dx + 1, y1, x2, y2, 0); } - - // Prevent the Image destructor from deleting the external buffer - img._imageData = nullptr; } void DisplayMan::scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer) { Image img(_vm); - img._imageData = buffer; + img.setData(buffer, false); if (x1 > x2) SWAP<uint16>(x1, x2); @@ -929,9 +923,6 @@ void DisplayMan::scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint1 rectFill(x1, y2 + dy + 1, x2, y2, 0); } - - // Prevent the Image destructor from deleting the external buffer - img._imageData = nullptr; } uint16 DisplayMan::fadeNumIn(uint16 num, uint16 res, uint16 counter) { diff --git a/engines/lab/image.cpp b/engines/lab/image.cpp index 08c4f6ca34..ec516718e8 100644 --- a/engines/lab/image.cpp +++ b/engines/lab/image.cpp @@ -48,10 +48,19 @@ Image::Image(Common::File *s, LabEngine *vm) : _vm(vm) { _imageData = new byte[size]; s->read(_imageData, size); + _autoFree = true; } Image::~Image() { - delete[] _imageData; + if (_autoFree) + delete[] _imageData; +} + +void Image::setData(byte *d, bool autoFree) { + if (_autoFree) + delete[] _imageData; + _imageData = d; + _autoFree = autoFree; } void Image::blitBitmap(uint16 srcX, uint16 srcY, Image *imgDest, diff --git a/engines/lab/image.h b/engines/lab/image.h index eaad75102d..0f985e09eb 100644 --- a/engines/lab/image.h +++ b/engines/lab/image.h @@ -47,11 +47,13 @@ public: uint16 _height; byte *_imageData; - Image(LabEngine *vm) : _width(0), _height(0), _imageData(nullptr), _vm(vm) {} - Image(int w, int h, byte *d, LabEngine *vm) : _width(w), _height(h), _imageData(d), _vm(vm) {} + Image(LabEngine *vm) : _width(0), _height(0), _imageData(nullptr), _vm(vm), _autoFree(true) {} + Image(int w, int h, byte *d, LabEngine *vm, bool autoFree = true) : _width(w), _height(h), _imageData(d), _vm(vm), _autoFree(autoFree) {} Image(Common::File *s, LabEngine *vm); ~Image(); + void setData(byte *d, bool autoFree = true); + /** * Draws an image to the screen. */ @@ -71,6 +73,9 @@ public: * Blits a piece of one image to another. */ void blitBitmap(uint16 srcX, uint16 srcY, Image *imgDest, uint16 destX, uint16 destY, uint16 width, uint16 height, byte masked); + +private: + bool _autoFree; ///< Free _imageData in destructor? }; } // End of namespace Lab diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp index e99c4dffa3..62eeb75bb3 100644 --- a/engines/lab/special.cpp +++ b/engines/lab/special.cpp @@ -134,7 +134,7 @@ void LabEngine::loadJournalData() { delete journalFile; _anim->_noPalChange = true; - _journalBackImage->_imageData = new byte[_graphics->_screenBytesPerPage]; + _journalBackImage->setData(new byte[_graphics->_screenBytesPerPage]); _graphics->readPict("P:Journal.pic", true, false, _journalBackImage->_imageData); _anim->_noPalChange = false; @@ -263,7 +263,7 @@ void LabEngine::doJournal() { _journalBackImage->_width = _graphics->_screenWidth; _journalBackImage->_height = _graphics->_screenHeight; - _journalBackImage->_imageData = nullptr; + _journalBackImage->setData(nullptr, true); updateMusicAndEvents(); loadJournalData(); @@ -276,8 +276,8 @@ void LabEngine::doJournal() { _event->mouseHide(); delete[] _blankJournal; - delete[] _journalBackImage->_imageData; - _blankJournal = _journalBackImage->_imageData = nullptr; + _blankJournal = nullptr; + _journalBackImage->setData(nullptr, true); _event->freeButtonList(&_journalButtonList); _graphics->freeFont(&_journalFont); diff --git a/engines/lab/tilepuzzle.cpp b/engines/lab/tilepuzzle.cpp index 8f21cee4b4..792989a07c 100644 --- a/engines/lab/tilepuzzle.cpp +++ b/engines/lab/tilepuzzle.cpp @@ -308,7 +308,7 @@ void TilePuzzle::changeCombination(uint16 number) { uint16 combnum = _combination[number]; - display._imageData = _vm->_graphics->getCurrentDrawingBuffer(); + display.setData(_vm->_graphics->getCurrentDrawingBuffer(), false); display._width = _vm->_graphics->_screenWidth; display._height = _vm->_graphics->_screenHeight; @@ -321,14 +321,11 @@ void TilePuzzle::changeCombination(uint16 number) { } else _vm->waitTOF(); - display._imageData = _vm->_graphics->getCurrentDrawingBuffer(); + display.setData(_vm->_graphics->getCurrentDrawingBuffer(), false); _vm->_graphics->scrollDisplayY(2, _vm->_utils->vgaScaleX(COMBINATION_X[number]), _vm->_utils->vgaScaleY(65), _vm->_utils->vgaScaleX(COMBINATION_X[number]) + (_numberImages[combnum])->_width - 1, _vm->_utils->vgaScaleY(65) + (_numberImages[combnum])->_height, buffer); _numberImages[combnum]->blitBitmap(0, (_numberImages[combnum])->_height - (2 * i), &(display), _vm->_utils->vgaScaleX(COMBINATION_X[number]), _vm->_utils->vgaScaleY(65), (_numberImages[combnum])->_width, 2, false); } - // Prevent the Image destructor from deleting the display buffer - display._imageData = nullptr; - delete[] buffer; bool unlocked = true; |