From 8aa3bbe29e6f91ee510bb3017eb7df9280b5a4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 12 May 2019 15:07:18 +0200 Subject: [PATCH] Fix zero division --- s3l.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/s3l.h b/s3l.h index 026cd09..4830090 100644 --- a/s3l.h +++ b/s3l.h @@ -1355,8 +1355,10 @@ void S3L_makeCameraMatrix(S3L_Transform3D cameraTransform, S3L_Mat4 *m) static inline void S3L_perspectiveDivide(S3L_Vec4 *vector, S3L_Unit focalLength) { - vector->x = (vector->x * focalLength) / vector->z; - vector->y = (vector->y * focalLength) / vector->z; + S3L_Unit divisor = S3L_nonZero(vector->z); + + vector->x = (vector->x * focalLength) / divisor; + vector->y = (vector->y * focalLength) / divisor; } void S3L_drawModelIndexed(