From 18a3f5c12592aadca684d256170f465a3d53ecd8 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 5 Aug 2016 14:44:31 +0600 Subject: [PATCH] WAGE: Fix crash in Brownie's Dream 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. --- engines/wage/gui-console.cpp | 15 ++++++++++++++- engines/wage/gui.cpp | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp index 2b364d36571d..2476a8c7fb0f 100644 --- a/engines/wage/gui-console.cpp +++ b/engines/wage/gui-console.cpp @@ -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; diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 212e75be484b..cd259e6dddec 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -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; }