From 406d09e08555501a60902608060d2fa61e075f21 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 19 Jan 2020 21:48:55 +0300 Subject: [PATCH] make plane zero if norm is zero after normalization --- include/cglm/plane.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/cglm/plane.h b/include/cglm/plane.h index 7a5291d..15ae580 100644 --- a/include/cglm/plane.h +++ b/include/cglm/plane.h @@ -30,7 +30,14 @@ CGLM_INLINE void glm_plane_normalize(vec4 plane) { - glm_vec4_scale(plane, 1.0f / glm_vec3_norm(plane), plane); + float norm; + + if ((norm = glm_vec3_norm(plane)) == 0.0f) { + glm_vec4_zero(plane); + return; + } + + glm_vec4_scale(plane, 1.0f / norm, plane); } #endif /* cglm_plane_h */