LAB: Avoid memory leaks with fonts
This commit is contained in:
parent
7f5826cfcb
commit
3fcd3c1526
5 changed files with 21 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -449,7 +449,7 @@ void Intro::introSequence() {
|
|||
_vm->_anim->_doBlack = true;
|
||||
}
|
||||
|
||||
_vm->_graphics->closeFont(msgFont);
|
||||
_vm->_graphics->closeFont(&msgFont);
|
||||
}
|
||||
|
||||
} // End of namespace Lab
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue