From 81262457d3819ed44d5bbe7ec1506eb526a323c7 Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Sun, 6 Mar 2005 00:46:13 +0000 Subject: Add extra safety checks from original games, to copyVirtScreenBuffers() svn-id: r16993 --- scumm/gfx.cpp | 29 +++++++++++++++++++++++++++-- scumm/gfx.h | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'scumm') diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp index 790faffce2..dec67688c5 100644 --- a/scumm/gfx.cpp +++ b/scumm/gfx.cpp @@ -1569,11 +1569,36 @@ void Gdi::drawBMAPObject(const byte *ptr, VirtScreen *vs, int obj, int x, int y, } } -void Gdi::copyVirtScreenBuffers(const Common::Rect &rect) { +void Gdi::copyVirtScreenBuffers(Common::Rect rect) { + byte *src, *dst; + VirtScreen *vs = &_vm->virtscr[0]; + + debug(1,"copyVirtScreenBuffers: Left %d Right %d Top %d Bottom %d", rect.left, rect.right, rect.top, rect.bottom); + + if (rect.top > vs->h || rect.bottom < 0) + return; + + if (rect.left > vs->w || rect.right < 0) + return; + + rect.left = MAX(0, (int)rect.left); + rect.left = MIN((int)rect.left, (int)vs->w - 1); + + rect.right = MAX(0, (int)rect.right); + rect.right = MIN((int)rect.right, (int)vs->w); + + rect.top = MAX(0, (int)rect.top); + rect.top = MIN((int)rect.top, (int)vs->h - 1); + + rect.bottom = MAX(0, (int)rect.bottom); + rect.bottom = MIN((int)rect.bottom, (int)vs->h); + const int rw = rect.width(); const int rh = rect.height(); - byte *src, *dst; + if (rw == 0 || rh == 0) + return; + src = _vm->virtscr[0].getBackPixels(rect.left, rect.top); dst = _vm->virtscr[0].getPixels(rect.left, rect.top); diff --git a/scumm/gfx.h b/scumm/gfx.h index 6bac0b54fa..a715d94651 100644 --- a/scumm/gfx.h +++ b/scumm/gfx.h @@ -279,7 +279,7 @@ public: void drawBMAPBg(const byte *ptr, VirtScreen *vs, int startstrip); void drawBMAPObject(const byte *ptr, VirtScreen *vs, int obj, int x, int y, int w, int h); - void copyVirtScreenBuffers(const Common::Rect &rect); + void copyVirtScreenBuffers(Common::Rect rect); void disableZBuffer() { _zbufferDisabled = true; } void enableZBuffer() { _zbufferDisabled = false; } -- cgit v1.2.3