Skip to content

Commit

Permalink
WAGE: Fix crash in Brownie's Dream
Browse files Browse the repository at this point in the history
I guess it would crash everywhere else as well, if console window would
be placed the same way. The problem is that console window goes off
screen a little in that game, but copyRectToScreen arguments are not
adjusted to stay within screen area.

This commit adds some checks and adjusts these arguments.
  • Loading branch information
Tkachov committed Aug 5, 2016
1 parent 8fcc919 commit 18a3f5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 14 additions & 1 deletion engines/wage/gui-console.cpp
Expand Up @@ -306,7 +306,20 @@ void Gui::drawInput() {

font->drawString(&_screen, _out[_inputTextLineNum], x, y, _screen.w, kColorBlack);

g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, _consoleWindow->getInnerDimensions().width(), font->getFontHeight());
int w = _consoleWindow->getInnerDimensions().width();
int h = font->getFontHeight();
if (x < 0) {
w += x;
x = 0;
}
if (y < 0) {
h += y;
y = 0;
}
if (x + w > _screen.w) w = _screen.w - x;
if (y + h > _screen.h) h = _screen.h - y;
if (w != 0 && h != 0)
g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, w, h);
}

_cursorX = font->getStringWidth(_out[_inputTextLineNum]) + kConHPadding;
Expand Down
15 changes: 13 additions & 2 deletions engines/wage/gui.cpp
Expand Up @@ -220,8 +220,19 @@ void Gui::draw() {
_wm.draw();

if (_cursorDirty && _cursorRect.left < _screen.w && _cursorRect.bottom < _screen.h) {
g_system->copyRectToScreen(_screen.getBasePtr(_cursorRect.left, _cursorRect.top), _screen.pitch,
_cursorRect.left, _cursorRect.top, _cursorRect.width(), _cursorRect.height());
int x = _cursorRect.left, y = _cursorRect.top, w = _cursorRect.width(), h = _cursorRect.height();
if (x < 0) {
w += x;
x = 0;
}
if (y < 0) {
h += y;
y = 0;
}
if (x + w > _screen.w) w = _screen.w - x;
if (y + h > _screen.h) h = _screen.h - y;
if (w != 0 && h != 0)
g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, w, h);

_cursorDirty = false;
}
Expand Down

0 comments on commit 18a3f5c

Please sign in to comment.