From 40dd214789ec627624a7703798907b7afbf50b8e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 19 May 2009 21:09:43 +0000 Subject: Start of fixing bug #2537054: "AGI: Using GMM to load causes graphics glitches" The engine still crashes when load from GMM occured with a text box on screen. svn-id: r40733 --- engines/agi/agi.h | 1 + engines/agi/keyboard.cpp | 2 +- engines/agi/saveload.cpp | 15 ++++++++++++++- engines/agi/text.cpp | 20 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 0e1c1fedf4..4f57f6c9fb 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -968,6 +968,7 @@ public: int messageBox(const char *); int selectionBox(const char *, const char **); void closeWindow(void); + void forgetWindow(void); void drawWindow(int, int, int, int); void printText(const char *, int, int, int, int, int, int, bool checkerboard = false); void printTextConsole(const char *, int, int, int, int, int); diff --git a/engines/agi/keyboard.cpp b/engines/agi/keyboard.cpp index 6aa7c0fe1f..3bbdc95192 100644 --- a/engines/agi/keyboard.cpp +++ b/engines/agi/keyboard.cpp @@ -379,7 +379,7 @@ int AgiEngine::waitKey() { } debugC(3, kDebugLevelInput, "waiting..."); - while (!(shouldQuit() || restartGame)) { + while (!(shouldQuit() || restartGame || getflag(fRestoreJustRan))) { _gfx->pollTimer(); /* msdos driver -> does nothing */ key = doPollKeyboard(); if (key == KEY_ENTER || key == KEY_ESCAPE || key == BUTTON_LEFT) diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 1b694e711c..bd0a0a5112 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -613,6 +613,16 @@ int AgiEngine::selectSlot() { _gfx->pollTimer(); /* msdos driver -> does nothing */ key = doPollKeyboard(); + + // It may happen that somebody will open GMM while + // this dialog is open, and load a game + // We are processing it here, effectively jumping + // out of the dead loop + if (getflag(fRestoreJustRan)) { + rc = -2; + goto getout; + } + switch (key) { case KEY_ENTER: rc = active; @@ -724,6 +734,7 @@ press: getout: closeWindow(); + return rc; } @@ -844,7 +855,9 @@ int AgiEngine::loadGameDialog() { slot = selectSlot(); if (slot < 0) { - messageBox("Game NOT restored."); + if (slot == -1) // slot = -2 when GMM was launched + messageBox("Game NOT restored."); + return errOK; } diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp index bf16f926b2..189a48c804 100644 --- a/engines/agi/text.cpp +++ b/engines/agi/text.cpp @@ -299,6 +299,11 @@ char *AgiEngine::wordWrapString(const char *s, int *len) { */ void AgiEngine::closeWindow() { debugC(4, kDebugLevelText, "closeWindow()"); + + if (getflag(fRestoreJustRan)) { + forgetWindow(); + } + _sprites->eraseBoth(); eraseTextbox(); /* remove window, if any */ _sprites->blitBoth(); @@ -306,6 +311,18 @@ void AgiEngine::closeWindow() { _game.hasWindow = false; } +/** + * Remove existing window without restoring anything + */ +void AgiEngine::forgetWindow() { + debugC(4, kDebugLevelText, "forgetWindow()"); + + free(_game.window.buffer); + _game.window.buffer = 0; + _game.window.active = false; + _game.hasWindow = false; +} + /** * Display a message box. * This function displays the specified message in a text box @@ -466,6 +483,9 @@ int AgiEngine::print(const char *p, int lin, int col, int len) { setvar(vKey, 0); do { + if (getflag(fRestoreJustRan)) + break; + mainCycle(); if (_game.keypress == KEY_ENTER) { debugC(4, kDebugLevelText, "KEY_ENTER"); -- cgit v1.2.3