diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index 939428e..036a56c 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -113,19 +113,29 @@ void BaseSurface::drawMouseCursorResource(MouseCursorResource &mouseCursorResour } } -void BaseSurface::copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect) { +bool 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 + bool result = true; byte *source = (byte*)sourceSurface->getBasePtr(sourceRect.x, sourceRect.y); byte *dest = (byte*)_surface->getBasePtr(x, y); int height = sourceRect.height; + int realY = y; while (height--) { for (int xc = 0; xc < sourceRect.width; xc++) - if (source[xc] != 0) - dest[xc] = source[xc]; + if (source[xc] != 0) { + if (realY >= _surface->h) { + debug("Out of bounds: Y=%d, %dx%d, %dx%d", realY, sourceRect.width, sourceRect.height, _surface->w, _surface->h); + result = false; + } else { + dest[xc] = source[xc]; + } + } source += sourceSurface->pitch; dest += _surface->pitch; + realY++; } ++_version; + return result; } // ShadowSurface @@ -172,7 +182,9 @@ void FontSurface::drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr) sourceRect.y = (chr / _charsPerRow) * _charHeight; sourceRect.width = _charWidth; sourceRect.height = _charHeight; - destSurface->copyFrom(_surface, x, y, sourceRect); + if (!destSurface->copyFrom(_surface, x, y, sourceRect)) { + debug("drawChar: Out of bounds detected while drawing '%c'", chr); + } } void FontSurface::drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen) { @@ -200,6 +212,7 @@ FontSurface *FontSurface::createFontSurface(NeverhoodEngine *vm, uint32 fileHash uint16 firstChar = fontData.getPoint(calcHash("meFirstChar")).x; uint16 charWidth = fontData.getPoint(calcHash("meCharWidth")).x; uint16 charHeight = fontData.getPoint(calcHash("meCharHeight")).x; + debug("charWidth = %d, charHeight = %d", charWidth, charHeight); NPointArray *tracking = fontData.getPointArray(calcHash("meTracking")); fontSprite.load(fileHash, true); fontSurface = new FontSurface(vm, tracking, 16, numRows, firstChar, charWidth, charHeight); diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h index 12fb2d2..ab4362b 100644 --- a/engines/neverhood/graphics.h +++ b/engines/neverhood/graphics.h @@ -93,7 +93,7 @@ public: void drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height); void drawAnimResource(AnimResource &animResource, uint frameIndex, bool flipX, bool flipY, int16 width, int16 height); void drawMouseCursorResource(MouseCursorResource &mouseCursorResource, int frameNum); - void copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect); + bool copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect); int getPriority() const { return _priority; } void setPriority(int priority) { _priority = priority; } NDrawRect& getDrawRect() { return _drawRect; } diff --git a/engines/neverhood/modules/module2200.cpp b/engines/neverhood/modules/module2200.cpp index 6618cb3..02719d2 100644 --- a/engines/neverhood/modules/module2200.cpp +++ b/engines/neverhood/modules/module2200.cpp @@ -1086,6 +1086,7 @@ void Scene2206::readClickedColumn() { setGlobalVar(V_CLICKED_COLUMN_INDEX, (_mouseClickPos.x - 354) / 96); if (getGlobalVar(V_CLICKED_COLUMN_INDEX) > 2) setGlobalVar(V_CLICKED_COLUMN_INDEX, 2); + debug("Clicked on %d, %d", _mouseClickPos.x, _mouseClickPos.y); setGlobalVar(V_CLICKED_COLUMN_ROW, (_mouseClickPos.y - 183) / 7); setGlobalVar(V_COLUMN_TEXT_NAME, calcHash("stLineagex")); setGlobalVar(V_COLUMN_BACK_NAME, 0); @@ -1432,6 +1433,7 @@ void Scene2208::drawRow(int16 rowIndex) { _background->getSurface()->copyFrom(_backgroundSurface->getSurface(), 0, y, sourceRect); if (rowIndex < (int)_strings.size()) { const char *text = _strings[rowIndex]; + debug("Row %d: Y=%d - %s", rowIndex, y, text); _fontSurface->drawString(_background->getSurface(), 95, y, (const byte*)text); } }