From 099b2e9249a81b1cc8e05774c0a85aa29d7853fe Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 15 Jan 2012 23:00:23 +0200 Subject: SCI: Properly handle negative coordinates in drawTextBitmap() This fixes occasional crashes when going to the map in GK1. Many thanks to digitall for finding this through Valgrind --- engines/sci/graphics/text32.cpp | 6 +++++- engines/sci/graphics/text32.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/engines/sci/graphics/text32.cpp b/engines/sci/graphics/text32.cpp index e7595fbdaf..e24799f6b8 100644 --- a/engines/sci/graphics/text32.cpp +++ b/engines/sci/graphics/text32.cpp @@ -173,7 +173,7 @@ void GfxText32::disposeTextBitmap(reg_t hunkId) { _segMan->freeHunkEntry(hunkId); } -void GfxText32::drawTextBitmap(uint16 x, uint16 y, Common::Rect planeRect, reg_t textObject) { +void GfxText32::drawTextBitmap(int16 x, int16 y, Common::Rect planeRect, reg_t textObject) { reg_t hunkId = readSelector(_segMan, textObject, SELECTOR(bitmap)); uint16 backColor = readSelectorValue(_segMan, textObject, SELECTOR(back)); // Sanity check: Check if the hunk is set. If not, either the game scripts @@ -181,6 +181,10 @@ void GfxText32::drawTextBitmap(uint16 x, uint16 y, Common::Rect planeRect, reg_t if (hunkId.isNull()) return; + // Negative coordinates indicate that text shouldn't be displayed + if (x < 0 || y < 0) + return; + byte *memoryPtr = _segMan->getHunkPointer(hunkId); if (!memoryPtr) diff --git a/engines/sci/graphics/text32.h b/engines/sci/graphics/text32.h index 3c1898858b..3505de85eb 100644 --- a/engines/sci/graphics/text32.h +++ b/engines/sci/graphics/text32.h @@ -34,7 +34,7 @@ public: ~GfxText32(); reg_t createTextBitmap(reg_t textObject, uint16 maxWidth = 0, uint16 maxHeight = 0, reg_t prevHunk = NULL_REG); void disposeTextBitmap(reg_t hunkId); - void drawTextBitmap(uint16 x, uint16 y, Common::Rect planeRect, reg_t textObject); + void drawTextBitmap(int16 x, int16 y, Common::Rect planeRect, reg_t textObject); int16 GetLongest(const char *text, int16 maxWidth, GfxFont *font); void kernelTextSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight); -- cgit v1.2.3