From 8fb07286cc5a6aaa508bcff5e8c91791e7303704 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 23 Oct 2006 23:12:12 +0000 Subject: Fix for bug #1582726 ("KYRA1: Crash when entering Castle screen"). svn-id: r24475 --- engines/kyra/animator.cpp | 21 ++++++++++++++------- engines/kyra/screen.cpp | 10 +++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/kyra/animator.cpp b/engines/kyra/animator.cpp index a11e56d65e..8d28bcc934 100644 --- a/engines/kyra/animator.cpp +++ b/engines/kyra/animator.cpp @@ -389,9 +389,8 @@ void ScreenAnimator::prepDrawAllObjects() { void ScreenAnimator::copyChangedObjectsForward(int refreshFlag) { debugC(9, kDebugLevelAnimator, "ScreenAnimator::copyChangedObjectsForward(%d)", refreshFlag); - AnimObject *curObject = _objectQueue; - while (curObject) { + for (AnimObject *curObject = _objectQueue; curObject; curObject = curObject->nextAnimObject) { if (curObject->active) { if (curObject->refreshFlag || refreshFlag) { int xpos = 0, ypos = 0, width = 0, height = 0; @@ -402,14 +401,22 @@ void ScreenAnimator::copyChangedObjectsForward(int refreshFlag) { if (xpos < 1) { xpos = 1; - } else if (xpos + width > 39) { - width = width - (xpos + width - 39); + } else if (xpos > 39) { + continue; + } + + if (xpos + width > 39) { + width = 39 - xpos; } if (ypos < 8) { ypos = 8; - } else if (ypos + height > 135) { - height = height - (ypos + height - 136); + } else if (ypos > 136) { + continue; + } + + if (ypos + height > 136) { + height = 136 - ypos; } _screen->copyRegion(xpos << 3, ypos, xpos << 3, ypos, width << 3, height, 2, 0, Screen::CR_CLIPPED); @@ -417,8 +424,8 @@ void ScreenAnimator::copyChangedObjectsForward(int refreshFlag) { _updateScreen = true; } } - curObject = curObject->nextAnimObject; } + if (_updateScreen) { _screen->updateScreen(); _updateScreen = false; diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index c36e8366c5..ebfcb63351 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -2340,15 +2340,19 @@ void Screen::addDirtyRect(int x, int y, int w, int h) { return; } - if (w == 0 || h == 0) + if (w == 0 || h == 0 || x >= SCREEN_W || y >= SCREEN_H || x + w < 0 || y + h < 0) return; - if (x < 0) + if (x < 0) { + w += x; x = 0; + } if (x + w >= 320) w = 320 - x; - if (y < 0) + if (y < 0) { + h += y; y = 0; + } if (y + h >= 200) h = 200 - y; -- cgit v1.2.3