From edea972b4be9dbeb8ff500a07e3fa58d301b5e36 Mon Sep 17 00:00:00 2001 From: Robert Göffringmann Date: Sat, 3 Jan 2004 10:49:08 +0000 Subject: eriktorbjorn's fix for a crash when sprite were completely outside of the screen svn-id: r12106 --- sword1/screen.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'sword1/screen.cpp') diff --git a/sword1/screen.cpp b/sword1/screen.cpp index b452e83037..b85d7c4836 100644 --- a/sword1/screen.cpp +++ b/sword1/screen.cpp @@ -709,21 +709,24 @@ void SwordScreen::spriteClipAndSet(uint16 *pSprX, uint16 *pSprY, uint16 *pSprWid *pSprWidth = (uint16)sprW; *pSprX = (uint16)sprX; *pSprY = (uint16)sprY; - - uint16 gridH = (*pSprHeight + SCRNGRID_Y - 1) / SCRNGRID_Y; - uint16 gridW = (*pSprWidth + SCRNGRID_X - 1) / SCRNGRID_X; - uint16 gridX = sprX / SCRNGRID_X; - uint16 gridY = sprY / SCRNGRID_Y; - uint8 *gridBuf = _screenGrid + gridX + gridY * _gridSizeX; - if (gridX + gridW > _gridSizeX) - gridW = _gridSizeX - gridX; - if (gridY + gridH > _gridSizeY) - gridH = _gridSizeY - gridY; - - for (uint16 cnty = 0; cnty < gridH; cnty++) { - for (uint16 cntx = 0; cntx < gridW; cntx++) - gridBuf[cntx] |= 0x80; - gridBuf += _gridSizeX; + + if (*pSprWidth && *pSprHeight) { + // sprite will be drawn, so mark it in the grid buffer + uint16 gridH = (*pSprHeight + SCRNGRID_Y - 1) / SCRNGRID_Y; + uint16 gridW = (*pSprWidth + SCRNGRID_X - 1) / SCRNGRID_X; + uint16 gridX = sprX / SCRNGRID_X; + uint16 gridY = sprY / SCRNGRID_Y; + uint8 *gridBuf = _screenGrid + gridX + gridY * _gridSizeX; + if (gridX + gridW > _gridSizeX) + gridW = _gridSizeX - gridX; + if (gridY + gridH > _gridSizeY) + gridH = _gridSizeY - gridY; + + for (uint16 cnty = 0; cnty < gridH; cnty++) { + for (uint16 cntx = 0; cntx < gridW; cntx++) + gridBuf[cntx] |= 0x80; + gridBuf += _gridSizeX; + } } } -- cgit v1.2.3