Avoid division by zero in cube map coordinates
authorJari Komppa <jari.komppa@siru.fi>
Wed, 24 Nov 2021 17:34:46 +0000 (19:34 +0200)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Thu, 9 Dec 2021 21:42:53 +0000 (21:42 +0000)
Cube map coordinates are calculated from 3-dimensional uv coordinates by
scaling two of the coordinates by the third. In case of using 0,0,0 as
the coordinates, a division by zero occurs. The result is undefined
behavior.

This change detects the division by zero event and returns uv
coordinates as 0,0. Since the behavior is undefined, it doesn't matter
what we return, but after this change the result should at least be
consistent.

Affects:
dEQP-GL*cube*

Components: Framework
VK-GL-CTS issue: 3351

Change-Id: I094a98f790a28bdf7b26ccb170888f2ea9c1e64c

framework/common/tcuTexture.cpp

index a41267e..7e84885 100644 (file)
@@ -2572,6 +2572,11 @@ Vec2 projectToFace (CubeFace face, const Vec3& coord)
                        DE_ASSERT(DE_FALSE);
        }
 
+       if (fabs(ma) < FLT_EPSILON)
+       {
+               return Vec2(0.0f);
+       }
+
        // Compute s, t
        s = ((sc / ma) + 1.0f) / 2.0f;
        t = ((tc / ma) + 1.0f) / 2.0f;