aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2015-12-01 02:17:26 +0200
committerWillem Jan Palenstijn2015-12-23 21:33:45 +0100
commit0fbf62f7f0115a0ad04b594f834e41cb7f719072 (patch)
tree4e3c812c6cc09621df4cf2bd5c6387e2d087a7f4 /engines
parent24684fe321f337caf96af917a3b7e647e8fd113b (diff)
downloadscummvm-rg350-0fbf62f7f0115a0ad04b594f834e41cb7f719072.tar.gz
scummvm-rg350-0fbf62f7f0115a0ad04b594f834e41cb7f719072.tar.bz2
scummvm-rg350-0fbf62f7f0115a0ad04b594f834e41cb7f719072.zip
LAB: Plug several font-related memory leaks. Some cleanup
Diffstat (limited to 'engines')
-rw-r--r--engines/lab/intro.cpp85
-rw-r--r--engines/lab/intro.h3
-rw-r--r--engines/lab/resource.cpp3
-rw-r--r--engines/lab/special.cpp17
-rw-r--r--engines/lab/text.cpp8
5 files changed, 55 insertions, 61 deletions
diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp
index b556501b17..e7f0187a73 100644
--- a/engines/lab/intro.cpp
+++ b/engines/lab/intro.cpp
@@ -42,7 +42,6 @@ extern char diffcmap[256 * 3];
extern uint16 *FadePalette;
Intro::Intro() {
- _msgfont = &_filler;
_quitIntro = false;
}
@@ -76,7 +75,7 @@ void Intro::introEatMessages() {
/*****************************************************************************/
/* Reads in a picture. */
/*****************************************************************************/
-void Intro::doPictText(const char *filename, bool isscreen) {
+void Intro::doPictText(const char *filename, TextFont *msgFont, bool isscreen) {
uint32 lastsecs = 0L, lastmicros = 0L, secs = 0L, micros = 0L;
IntuiMessage *msg;
char path[50] = "Lab:rooms/Intro/";
@@ -118,7 +117,7 @@ void Intro::doPictText(const char *filename, bool isscreen) {
g_lab->setAPen(7);
g_lab->rectFill(VGAScaleX(10), VGAScaleY(10), VGAScaleX(310), VGAScaleY(190));
- Drawn = flowText(_msgfont, (!g_lab->_isHiRes) * -1, 5, 7, false, false, true, true, VGAScaleX(14), VGAScaleY(11), VGAScaleX(306), VGAScaleY(189), (char *)curplace);
+ Drawn = flowText(msgFont, (!g_lab->_isHiRes) * -1, 5, 7, false, false, true, true, VGAScaleX(14), VGAScaleY(11), VGAScaleX(306), VGAScaleY(189), (char *)curplace);
fade(true, 0);
} else {
Drawn = g_lab->longDrawMessage((char *)curplace);
@@ -347,7 +346,7 @@ void Intro::introSequence() {
blackAllScreen();
g_lab->_music->updateMusic();
- _msgfont = g_lab->_resource->getFont("P:Map.fon");
+ TextFont *msgFont = g_lab->_resource->getFont("P:Map.fon");
nopalchange = true;
nReadPict("Intro.1", true);
@@ -359,9 +358,9 @@ void Intro::introSequence() {
(diffcmap[i * 3 + 2] >> 2);
}
- doPictText("i.1", true);
- doPictText("i.2A", true);
- doPictText("i.2B", true);
+ doPictText("i.1", msgFont, true);
+ doPictText("i.2A", msgFont, true);
+ doPictText("i.2B", msgFont, true);
freeAllStolenMem();
@@ -370,28 +369,28 @@ void Intro::introSequence() {
_introDoBlack = true;
nReadPict("Station1", true);
- doPictText("i.3", false);
+ doPictText("i.3", msgFont, false);
nReadPict("Station2", true);
- doPictText("i.4", false);
+ doPictText("i.4", msgFont, false);
nReadPict("Stiles4", true);
- doPictText("i.5", false);
+ doPictText("i.5", msgFont, false);
nReadPict("Stiles3", true);
- doPictText("i.6", false);
+ doPictText("i.6", msgFont, false);
nReadPict("Platform2", true);
- doPictText("i.7", false);
+ doPictText("i.7", msgFont, false);
nReadPict("Subway.1", true);
- doPictText("i.8", false);
+ doPictText("i.8", msgFont, false);
nReadPict("Subway.2", true);
- doPictText("i.9", false);
- doPictText("i.10", false);
- doPictText("i.11", false);
+ doPictText("i.9", msgFont, false);
+ doPictText("i.10", msgFont, false);
+ doPictText("i.11", msgFont, false);
if (!_quitIntro)
for (uint16 i = 0; i < 50; i++) {
@@ -401,60 +400,60 @@ void Intro::introSequence() {
g_lab->_music->updateMusic();
g_lab->waitTOF();
g_lab->setPalette(diffcmap, 256);
- g_lab-> waitTOF();
+ g_lab->waitTOF();
g_lab->waitTOF();
}
- doPictText("i.12", false);
- doPictText("i.13", false);
+ doPictText("i.12", msgFont, false);
+ doPictText("i.13", msgFont, false);
_introDoBlack = false;
nReadPict("Daed0", true);
- doPictText("i.14", false);
+ doPictText("i.14", msgFont, false);
nReadPict("Daed1", true);
- doPictText("i.15", false);
+ doPictText("i.15", msgFont, false);
nReadPict("Daed2", true);
- doPictText("i.16", false);
- doPictText("i.17", false);
- doPictText("i.18", false);
+ doPictText("i.16", msgFont, false);
+ doPictText("i.17", msgFont, false);
+ doPictText("i.18", msgFont, false);
nReadPict("Daed3", true);
- doPictText("i.19", false);
- doPictText("i.20", false);
+ doPictText("i.19", msgFont, false);
+ doPictText("i.20", msgFont, false);
nReadPict("Daed4", true);
- doPictText("i.21", false);
+ doPictText("i.21", msgFont, false);
nReadPict("Daed5", true);
- doPictText("i.22", false);
- doPictText("i.23", false);
- doPictText("i.24", false);
+ doPictText("i.22", msgFont, false);
+ doPictText("i.23", msgFont, false);
+ doPictText("i.24", msgFont, false);
nReadPict("Daed6", true);
- doPictText("i.25", false);
- doPictText("i.26", false);
+ doPictText("i.25", msgFont, false);
+ doPictText("i.26", msgFont, false);
nReadPict("Daed7", false);
- doPictText("i.27", false);
- doPictText("i.28", false);
+ doPictText("i.27", msgFont, false);
+ doPictText("i.28", msgFont, false);
stopDiffEnd();
nReadPict("Daed8", true);
- doPictText("i.29", false);
- doPictText("i.30", false);
+ doPictText("i.29", msgFont, false);
+ doPictText("i.30", msgFont, false);
nReadPict("Daed9", true);
- doPictText("i.31", false);
- doPictText("i.32", false);
- doPictText("i.33", false);
+ doPictText("i.31", msgFont, false);
+ doPictText("i.32", msgFont, false);
+ doPictText("i.33", msgFont, false);
nReadPict("Daed9a", true);
nReadPict("Daed10", true);
- doPictText("i.34", false);
- doPictText("i.35", false);
- doPictText("i.36", false);
+ doPictText("i.34", msgFont, false);
+ doPictText("i.35", msgFont, false);
+ doPictText("i.36", msgFont, false);
nReadPict("SubX", true);
@@ -463,6 +462,8 @@ void Intro::introSequence() {
g_lab->rectFill(0, 0, g_lab->_screenWidth - 1, g_lab->_screenHeight - 1);
DoBlack = true;
}
+
+ closeFont(msgFont);
}
} // End of namespace Lab
diff --git a/engines/lab/intro.h b/engines/lab/intro.h
index 724fedaa7e..2979bcd334 100644
--- a/engines/lab/intro.h
+++ b/engines/lab/intro.h
@@ -43,11 +43,10 @@ public:
private:
void introEatMessages();
- void doPictText(const char *Filename, bool isscreen);
+ void doPictText(const char *Filename, TextFont *msgFont, bool isscreen);
void musicDelay();
void nReadPict(const char *Filename, bool PlayOnce);
- TextFont _filler, *_msgfont;
bool _quitIntro, _introDoBlack;
};
diff --git a/engines/lab/resource.cpp b/engines/lab/resource.cpp
index 0c60924cda..b1ad5284ba 100644
--- a/engines/lab/resource.cpp
+++ b/engines/lab/resource.cpp
@@ -67,14 +67,13 @@ TextFont *Resource::getFont(const char *fileName) {
_vm->_music->updateMusic();
- TextFont *textfont = (TextFont *)malloc(sizeof(TextFont));
+ TextFont *textfont = new TextFont();
textfont->DataLength = fileSize - headerSize;
textfont->Height = dataFile->readUint16LE();
dataFile->read(textfont->Widths, 256);
for (int i = 0; i < 256; i++)
textfont->Offsets[i] = dataFile->readUint16LE();
dataFile->skip(4);
- // TODO: Fix memory leak!!
textfont->data = new byte[textfont->DataLength + 4];
dataFile->read(textfont->data, textfont->DataLength);
return textfont;
diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp
index 6be525dd30..70ec15af06 100644
--- a/engines/lab/special.cpp
+++ b/engines/lab/special.cpp
@@ -461,8 +461,7 @@ void doNotes() {
flowText(noteFont, -2 + SVGACord(1), 0, 0, false, false, true, true, VGAScaleX(25) + SVGACord(15), VGAScaleY(50), VGAScaleX(295) - SVGACord(15), VGAScaleY(148), ntext);
g_lab->setPalette(diffcmap, 256);
- delete[] noteFont->data;
- free(noteFont);
+ closeFont(noteFont);
delete[] ntext;
}
@@ -480,8 +479,7 @@ void doWestPaper() {
paperFont = g_lab->_resource->getFont("P:News22.fon");
ntext = g_lab->_resource->getText("Lab:Rooms/Date");
flowText(paperFont, 0, 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(77) + SVGACord(2), VGAScaleX(262), VGAScaleY(91), ntext);
- delete[] paperFont->data;
- free(paperFont);
+ closeFont(paperFont);
delete[] ntext;
paperFont = g_lab->_resource->getFont("P:News32.fon");
@@ -493,8 +491,7 @@ void doWestPaper() {
flowText(paperFont, -8 - SVGACord(1), 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(86) - SVGACord(2), VGAScaleX(262), VGAScaleY(132), ntext);
} else
y = 115 - SVGACord(5);
- delete[] paperFont->data;
- free(paperFont);
+ closeFont(paperFont);
delete[] ntext;
paperFont = g_lab->_resource->getFont("P:Note.fon");
@@ -504,8 +501,7 @@ void doWestPaper() {
ntext = g_lab->_resource->getText("Lab:Rooms/Col2");
CharsPrinted = flowText(paperFont, -4, 0, 0, false, false, false, true, VGAScaleX(162), VGAScaleY(y), VGAScaleX(275), VGAScaleY(148), ntext);
delete[] ntext;
- delete[] paperFont->data;
- free(paperFont);
+ closeFont(paperFont);
g_lab->setPalette(diffcmap, 256);
freeAllStolenMem();
@@ -520,7 +516,7 @@ static bool loadJournalData() {
Gadget *TopGadget = &BackG;
bool bridge, dirty, news, clean;
- journalFont = g_lab->_resource->getFont("P:Journal.fon");
+ journalFont = g_lab->_resource->getFont("P:Journal.fon"); // FIXME: memory leak
g_lab->_music->updateMusic();
@@ -1024,8 +1020,7 @@ void LabEngine::doMonitor(char *background, char *textfile, bool isinteractive,
fade(false, 0);
_event->mouseHide();
delete[] ntext;
- delete[] monitorFont->data;
- free(monitorFont);
+ closeFont(monitorFont);
freeAllStolenMem();
setAPen(0);
diff --git a/engines/lab/text.cpp b/engines/lab/text.cpp
index 3fc1b1a9c4..a7b41f1752 100644
--- a/engines/lab/text.cpp
+++ b/engines/lab/text.cpp
@@ -38,19 +38,19 @@ namespace Lab {
/*****************************************************************************/
/* Closes a font and frees all memory associated with it. */
/*****************************************************************************/
-void closeFont(struct TextFont *tf) {
+void closeFont(TextFont *tf) {
if (tf) {
if (tf->data && tf->DataLength)
delete[] tf->data;
- free(tf);
+ delete tf;
}
}
/*****************************************************************************/
/* Returns the length of a text in the specified font. */
/*****************************************************************************/
-uint16 textLength(struct TextFont *tf, const char *text, uint16 numchars) {
+uint16 textLength(TextFont *tf, const char *text, uint16 numchars) {
uint16 length = 0;
if (tf) {
@@ -66,7 +66,7 @@ uint16 textLength(struct TextFont *tf, const char *text, uint16 numchars) {
/*****************************************************************************/
/* Returns the height of a specified font. */
/*****************************************************************************/
-uint16 textHeight(struct TextFont *tf) {
+uint16 textHeight(TextFont *tf) {
return (tf) ? tf->Height : 0;
}