From bdee71f27922d1ba146323374e4501ec462d687d Mon Sep 17 00:00:00 2001 From: johndoe123 Date: Thu, 26 Jun 2014 19:16:44 +0200 Subject: NEVERHOOD: Implement clipping in BaseSurface::copyFrom This should hopefully fix the crashes in the Hall of Records as mentioned in bug #6513. --- engines/neverhood/graphics.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index 939428ed19..89792d2659 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -114,7 +114,15 @@ void BaseSurface::drawMouseCursorResource(MouseCursorResource &mouseCursorResour } void BaseSurface::copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect) { - // Copy a rectangle from sourceSurface, no clipping is performed, 0 is the transparent color + // Copy a rectangle from sourceSurface, 0 is the transparent color + // Clipping is performed against the right/bottom border since x, y will always be >= 0 + + if (x + sourceRect.width > _surface->w) + sourceRect.width = _surface->w - x - 1; + + if (y + sourceRect.height > _surface->h) + sourceRect.height = _surface->h - y - 1; + byte *source = (byte*)sourceSurface->getBasePtr(sourceRect.x, sourceRect.y); byte *dest = (byte*)_surface->getBasePtr(x, y); int height = sourceRect.height; -- cgit v1.2.3