fixed Sky memory leaks on quitting

svn-id: r19791
This commit is contained in:
Robert Göffringmann 2005-12-13 14:31:13 +00:00
parent 5517880300
commit c477d54570
4 changed files with 35 additions and 25 deletions

View File

@ -237,7 +237,12 @@ void Control::removePanel(void) {
delete _restartPanButton; delete _fxPanButton;
delete _musicPanButton; delete _bodge;
delete _yesNo; delete _text;
delete _statusBar;
delete _statusBar; delete _restoreButton;
if (_textSprite) {
free(_textSprite);
_textSprite = NULL;
}
}
void Control::initPanel(void) {
@ -318,13 +323,16 @@ void Control::initPanel(void) {
_restorePanLookList[6] = _autoSaveButton;
_statusBar = new ControlStatus(_skyText, _system, _screenBuf);
_textSprite = NULL;
}
void Control::buttonControl(ConResource *pButton) {
char autoSave[] = "Restore Autosave";
if (pButton == NULL) {
if (_textSprite) free(_textSprite);
if (_textSprite)
free(_textSprite);
_textSprite = NULL;
_curButtonText = 0;
_text->setSprite(NULL);
@ -431,7 +439,6 @@ void Control::doLoadSavePanel(void) {
_skyMouse->spriteMouse(MOUSE_NORMAL, 0, 0);
_lastButton = -1;
_curButtonText = 0;
_textSprite = NULL;
saveRestorePanel(false);
@ -469,7 +476,6 @@ void Control::doControlPanel(void) {
bool quitPanel = false;
_lastButton = -1;
_curButtonText = 0;
_textSprite = NULL;
uint16 clickRes = 0;
while (!quitPanel && !SkyEngine::_systemVars.quitGame) {
@ -841,7 +847,7 @@ uint16 Control::saveRestorePanel(bool allowSave) {
bool refreshNames = true;
bool refreshAll = true;
uint16 clickRes = 0;
while (!quitPanel) {
while (!quitPanel && !SkyEngine::_systemVars.quitGame) {
clickRes = 0;
if (refreshNames || refreshAll) {
if (refreshAll) {
@ -920,7 +926,8 @@ uint16 Control::saveRestorePanel(bool allowSave) {
refreshNames = true;
}
}
if (!haveButton) buttonControl(NULL);
if (!haveButton)
buttonControl(NULL);
}
for (cnt = 0; cnt < MAX_ON_SCREEN + 1; cnt++)

View File

@ -90,6 +90,10 @@ Logic::Logic(SkyCompact *skyCompact, Screen *skyScreen, Disk *skyDisk, Text *sky
Logic::~Logic(void) {
delete _skyGrid;
delete _skyAutoRoute;
for (int i = 0; i < ARRAYSIZE(_moduleList); i++)
if (_moduleList[i])
free(_moduleList[i]);
}
void Logic::initScreen0(void) {

View File

@ -91,6 +91,8 @@ Screen::~Screen(void) {
free(_gameGrid);
if (_currentScreen)
free(_currentScreen);
if (_scrollScreen)
free(_scrollScreen);
}
void Screen::clearScreen(void) {
@ -246,14 +248,7 @@ void Screen::fnDrawScreen(uint32 palette, uint32 scroll) {
void Screen::fnFadeDown(uint32 scroll) {
if (scroll && (!(SkyEngine::_systemVars.systemFlags & SF_NO_SCROLL))) {
// scrolling is performed by fnFadeUp. It's just prepared here
_scrollScreen = _currentScreen;
_currentScreen = (uint8 *)malloc(FULL_SCREEN_WIDTH * FULL_SCREEN_HEIGHT);
// the game will draw the new room into _currentScreen which
// will be scrolled into the visible screen by fnFadeUp
// fnFadeUp also frees the _scrollScreen
} else {
if (((scroll != 123) && (scroll != 321)) || (SkyEngine::_systemVars.systemFlags & SF_NO_SCROLL)) {
uint32 delayTime = _system->getMillis();
for (uint8 cnt = 0; cnt < 32; cnt++) {
delayTime += 20;
@ -265,6 +260,13 @@ void Screen::fnFadeDown(uint32 scroll) {
waitTime = 0;
_system->delayMillis((uint)waitTime);
}
} else {
// scrolling is performed by fnFadeUp. It's just prepared here
_scrollScreen = _currentScreen;
_currentScreen = (uint8 *)malloc(FULL_SCREEN_WIDTH * FULL_SCREEN_HEIGHT);
// the game will draw the new room into _currentScreen which
// will be scrolled into the visible screen by fnFadeUp
// fnFadeUp also frees the _scrollScreen
}
}
@ -325,9 +327,8 @@ void Screen::fnFadeUp(uint32 palNum, uint32 scroll) {
//_currentScreen points to new screen,
//_scrollScreen points to graphic showing old room
if ((scroll != 123) && (scroll != 321)) {
if ((scroll != 123) && (scroll != 321))
scroll = 0;
}
if ((scroll == 0) || (SkyEngine::_systemVars.systemFlags & SF_NO_SCROLL)) {
uint8 *palette = (uint8 *)_skyCompact->fetchCpt(palNum);
@ -342,10 +343,7 @@ void Screen::fnFadeUp(uint32 palNum, uint32 scroll) {
paletteFadeUp(palette);
#endif
} else if (scroll == 123) { // scroll left (going right)
if (!_currentScreen)
error("Screen::fnFadeUp[Scroll L]: _currentScreen is NULL");
if (!_scrollScreen)
error("Screen::fnFadeUp[Scroll L]: _scrollScreen is NULL");
assert(_currentScreen && _scrollScreen);
uint8 *scrNewPtr, *scrOldPtr;
for (uint8 scrollCnt = 0; scrollCnt < (GAME_SCREEN_WIDTH / SCROLL_JUMP) - 1; scrollCnt++) {
scrNewPtr = _currentScreen + scrollCnt * SCROLL_JUMP;
@ -360,12 +358,8 @@ void Screen::fnFadeUp(uint32 palNum, uint32 scroll) {
waitForTimer();
}
showScreen(_currentScreen);
free(_scrollScreen);
} else if (scroll == 321) { // scroll right (going left)
if (!_currentScreen)
error("Screen::fnFadeUp[Scroll R]: _currentScreen is NULL");
if (!_scrollScreen)
error("Screen::fnFadeUp[Scroll R]: _scrollScreen is NULL");
assert(_currentScreen && _scrollScreen);
uint8 *scrNewPtr, *scrOldPtr;
for (uint8 scrollCnt = 0; scrollCnt < (GAME_SCREEN_WIDTH / SCROLL_JUMP) - 1; scrollCnt++) {
scrNewPtr = _currentScreen + GAME_SCREEN_WIDTH - (scrollCnt + 1) * SCROLL_JUMP;
@ -380,7 +374,10 @@ void Screen::fnFadeUp(uint32 palNum, uint32 scroll) {
waitForTimer();
}
showScreen(_currentScreen);
}
if (_scrollScreen) {
free(_scrollScreen);
_scrollScreen = NULL;
}
}

View File

@ -133,6 +133,8 @@ SkyEngine::~SkyEngine() {
delete _skyScreen;
delete _debugger;
delete _skyDisk;
delete _skyControl;
delete _skyCompact;
for (int i = 0; i < 300; i++)
if (_itemList[i])