diff options
author | Strangerke | 2015-12-19 13:08:54 +0100 |
---|---|---|
committer | Willem Jan Palenstijn | 2015-12-23 21:35:30 +0100 |
commit | 3fcd3c15262adb1b4ac9f69475df2a4145c450d3 (patch) | |
tree | 08542f2438b8e3a1ea9bc711392cd9dcf7421619 | |
parent | 7f5826cfcb72d1375d6c24b153a446fd9c92f623 (diff) | |
download | scummvm-rg350-3fcd3c15262adb1b4ac9f69475df2a4145c450d3.tar.gz scummvm-rg350-3fcd3c15262adb1b4ac9f69475df2a4145c450d3.tar.bz2 scummvm-rg350-3fcd3c15262adb1b4ac9f69475df2a4145c450d3.zip |
LAB: Avoid memory leaks with fonts
-rw-r--r-- | engines/lab/dispman.cpp | 11 | ||||
-rw-r--r-- | engines/lab/dispman.h | 2 | ||||
-rw-r--r-- | engines/lab/engine.cpp | 5 | ||||
-rw-r--r-- | engines/lab/intro.cpp | 2 | ||||
-rw-r--r-- | engines/lab/special.cpp | 15 |
5 files changed, 21 insertions, 14 deletions
diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp index c928649c3a..ecf867b7cb 100644 --- a/engines/lab/dispman.cpp +++ b/engines/lab/dispman.cpp @@ -633,12 +633,13 @@ void DisplayMan::overlayRect(uint16 penColor, uint16 x1, uint16 y1, uint16 x2, u /** * Closes a font and frees all memory associated with it. */ -void DisplayMan::closeFont(TextFont *font) { - if (font) { - if (font->_data && font->_dataLength) - delete[] font->_data; +void DisplayMan::closeFont(TextFont **font) { + if (*font) { + if ((*font)->_data) + delete[] (*font)->_data; - delete font; + delete *font; + *font = nullptr; } } diff --git a/engines/lab/dispman.h b/engines/lab/dispman.h index 1b90484d9d..e89bcabd41 100644 --- a/engines/lab/dispman.h +++ b/engines/lab/dispman.h @@ -130,7 +130,7 @@ public: void scrollDisplayX(int16 dx, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer); void scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer); void fade(bool fadein, uint16 res); - void closeFont(TextFont *font); + void closeFont(TextFont **font); uint16 textLength(TextFont *font, const char *text, uint16 numChars); uint16 textHeight(TextFont *tf); void drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numChars); diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index 52f8525b0d..053e961aa6 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -1124,6 +1124,9 @@ void LabEngine::go() { _graphics->setUpScreens(); _event->initMouse(); + if (_msgFont) + _graphics->closeFont(&_msgFont); + if (getPlatform() != Common::kPlatformAmiga) _msgFont = _resource->getFont("F:AvanteG.12"); else @@ -1137,7 +1140,7 @@ void LabEngine::go() { _event->mouseShow(); mainGameLoop(); - _graphics->closeFont(_msgFont); + _graphics->closeFont(&_msgFont); _graphics->freePict(); freeScreens(); diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp index 9fbd0b3def..2d2c55d09d 100644 --- a/engines/lab/intro.cpp +++ b/engines/lab/intro.cpp @@ -449,7 +449,7 @@ void Intro::introSequence() { _vm->_anim->_doBlack = true; } - _vm->_graphics->closeFont(msgFont); + _vm->_graphics->closeFont(&msgFont); } } // End of namespace Lab diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp index 4ea6843d98..7bb09e6a91 100644 --- a/engines/lab/special.cpp +++ b/engines/lab/special.cpp @@ -57,7 +57,7 @@ void LabEngine::doNotes() { Common::Rect textRect = Common::Rect(_utils->vgaScaleX(25) + _utils->svgaCord(15), _utils->vgaScaleY(50), _utils->vgaScaleX(295) - _utils->svgaCord(15), _utils->vgaScaleY(148)); _graphics->flowText(noteFont, -2 + _utils->svgaCord(1), 0, 0, false, false, true, true, textRect, noteText.c_str()); _graphics->setPalette(_anim->_diffPalette, 256); - _graphics->closeFont(noteFont); + _graphics->closeFont(¬eFont); } /** @@ -70,7 +70,7 @@ void LabEngine::doWestPaper() { Common::Rect textRect = Common::Rect(_utils->vgaScaleX(57), _utils->vgaScaleY(77) + _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(91)); _graphics->flowText(paperFont, 0, 0, 0, false, true, false, true, textRect, paperText.c_str()); - _graphics->closeFont(paperFont); + _graphics->closeFont(&paperFont); paperFont = _resource->getFont("F:News32.fon"); paperText = _resource->getText("Lab:Rooms/Headline"); @@ -88,14 +88,14 @@ void LabEngine::doWestPaper() { } else y = 115 - _utils->svgaCord(5); - _graphics->closeFont(paperFont); + _graphics->closeFont(&paperFont); paperFont = _resource->getFont("F:Note.fon"); paperText = _resource->getText("Lab:Rooms/Col1"); charsPrinted = _graphics->flowText(paperFont, -4, 0, 0, false, false, false, true, _utils->vgaRectScale(45, y, 158, 148), paperText.c_str()); paperText = _resource->getText("Lab:Rooms/Col2"); charsPrinted = _graphics->flowText(paperFont, -4, 0, 0, false, false, false, true, _utils->vgaRectScale(162, y, 275, 148), paperText.c_str()); - _graphics->closeFont(paperFont); + _graphics->closeFont(&paperFont); _graphics->setPalette(_anim->_diffPalette, 256); } @@ -104,6 +104,9 @@ void LabEngine::doWestPaper() { * Loads in the data for the journal. */ void LabEngine::loadJournalData() { + if (_journalFont) + _graphics->closeFont(&_journalFont); + _journalFont = _resource->getFont("F:Journal.fon"); _music->updateMusic(); @@ -308,7 +311,7 @@ void LabEngine::doJournal() { delete[] _blankJournal; delete[] _journalBackImage->_imageData; _event->freeButtonList(&_journalButtonList); - _graphics->closeFont(_journalFont); + _graphics->closeFont(&_journalFont); _screenImage->_imageData = _graphics->getCurrentDrawingBuffer(); @@ -503,7 +506,7 @@ void LabEngine::doMonitor(Common::String background, Common::String textfile, bo processMonitor((char *)ntext.c_str(), monitorFont, isinteractive, scaledRect); _graphics->fade(false, 0); _event->mouseHide(); - _graphics->closeFont(monitorFont); + _graphics->closeFont(&monitorFont); _graphics->setPen(0); _graphics->rectFill(0, 0, _graphics->_screenWidth - 1, _graphics->_screenHeight - 1); |