From 1ab811c4ec3bdbc97d56fa648ea66954bff3f467 Mon Sep 17 00:00:00 2001 From: David Eriksson Date: Tue, 28 Oct 2003 14:19:11 +0000 Subject: Safer use of dynalum. svn-id: r10991 --- queen/display.cpp | 20 +++++++++++++++++--- queen/display.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'queen') diff --git a/queen/display.cpp b/queen/display.cpp index be4f7a346b..29730132fd 100644 --- a/queen/display.cpp +++ b/queen/display.cpp @@ -146,11 +146,15 @@ void Display::dynalumInit(Resource *resource, const char *roomName, uint16 roomN // FIXME: are these tests really needed ? if (roomNum < 90 || ((roomNum > 94) && (roomNum < 114))) { char filename[20]; + sprintf(filename, "%s.msk", roomName); - if (resource->exists(filename)) + _dynalum.haveMsk = resource->exists(filename); + if (_dynalum.haveMsk) resource->loadFile(filename, 0, (uint8*)_dynalum.msk); + sprintf(filename, "%s.lum", roomName); - if (resource->exists(filename)) + _dynalum.haveLum = resource->exists(filename); + if (_dynalum.haveLum) resource->loadFile(filename, 0, (uint8*)_dynalum.lum); } } @@ -158,13 +162,23 @@ void Display::dynalumInit(Resource *resource, const char *roomName, uint16 roomN void Display::dynalumUpdate(int x, int y) { + if (!_dynalum.haveMsk) + return; + if (x >= _bdWidth) { x = _bdWidth; } if (y >= ROOM_ZONE_HEIGHT - 1) { y = ROOM_ZONE_HEIGHT - 1; } - uint8 colMask = _dynalum.msk[(y / 4) * 160 + (x / 4)]; + + unsigned offset = (y / 4) * 160 + (x / 4); + if (offset >= sizeof(_dynalum.msk)) { + debug(0, "Graphics::dynalumUpdate(%d, %d) - invalid offset: %08x", x, y, offset); + return; + } + + uint8 colMask = _dynalum.msk[offset]; debug(9, "Graphics::dynalumUpdate(%d, %d) - colMask = %d", x, y, colMask); if (colMask != _dynalum.prevColMask) { diff --git a/queen/display.h b/queen/display.h index 5c5a2e2f6b..24608b3345 100644 --- a/queen/display.h +++ b/queen/display.h @@ -43,6 +43,8 @@ enum JoePalette { struct Dynalum { + bool haveMsk; + bool haveLum; uint8 msk[50 * 160]; int8 lum[8 * 3]; uint8 prevColMask; -- cgit v1.2.3