From a5fa09de3500f531adbc1b49bf33c9cd5ef22325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 29 Sep 2018 13:09:41 +0200 Subject: [PATCH] Fix division by zero --- raycastlib.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 69be012..5ca2cea 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -1125,10 +1125,11 @@ static inline int16_t _RCL_drawHorizontal( if (doCoords) /*constant condition - compiler should optimize it out*/\ {\ RCL_Unit d = _RCL_floorPixelDistances[i];\ + RCL_Unit d2 = RCL_nonZero(pixelInfo->hit.distance);\ pixelInfo->texCoords.x =\ - _RCL_camera.position.x + ((d * dx) / (pixelInfo->hit.distance));\ + _RCL_camera.position.x + ((d * dx) / d2);\ pixelInfo->texCoords.y =\ - _RCL_camera.position.y + ((d * dy) / (pixelInfo->hit.distance));\ + _RCL_camera.position.y + ((d * dy) / d2);\ }\ RCL_PIXEL_FUNCTION(pixelInfo);\ }\ @@ -1284,6 +1285,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t { hit = hits[j]; distance = hit.distance; + p.hit = hit; fWallHeight = _RCL_floorFunction(hit.square.x,hit.square.y); fZ2World = fWallHeight - _RCL_camera.height; @@ -1328,8 +1330,6 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t p.depth = 0; #endif - p.hit = hit; - limit = _RCL_drawHorizontal(fPosY,fZ1Screen,cPosY + 1, _RCL_camera.resolution.y,fZ1World,-1,RCL_COMPUTE_FLOOR_DEPTH, // ^ purposfully allow outside screen bounds