From b7af9831da9d460509aafdac58b9ff6c927744f3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 May 2009 04:54:45 +0000 Subject: [PATCH] Fixes for the backupBackground method when X < 0 svn-id: r40590 --- engines/cruise/backgroundIncrust.cpp | 6 +++++- engines/cruise/backgroundIncrust.h | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/engines/cruise/backgroundIncrust.cpp b/engines/cruise/backgroundIncrust.cpp index 8d4bb701282..776aa6305de 100644 --- a/engines/cruise/backgroundIncrust.cpp +++ b/engines/cruise/backgroundIncrust.cpp @@ -52,7 +52,11 @@ void backupBackground(backgroundIncrustStruct *pIncrust, int X, int Y, int width pIncrust->ptr = (uint8*)malloc(width * height); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - pIncrust->ptr[i * width + j] = pBackground[(i+Y) * 320 + j + X]; + int xp = j + X; + int yp = i + Y; + + pIncrust->ptr[i * width + j] = ((xp < 0) || (yp < 0) || (xp >= 320) || (yp >= 200)) ? + 0 : pBackground[yp * 320 + xp]; } } } diff --git a/engines/cruise/backgroundIncrust.h b/engines/cruise/backgroundIncrust.h index 81b53815d90..92db79cf13a 100644 --- a/engines/cruise/backgroundIncrust.h +++ b/engines/cruise/backgroundIncrust.h @@ -35,8 +35,8 @@ struct backgroundIncrustStruct { uint16 objectIdx; int16 type; uint16 overlayIdx; - uint16 X; - uint16 Y; + int16 X; + int16 Y; uint16 field_E; uint16 scale; uint16 backgroundIdx;