From c670cd45d984ae67fa3da8da89ee713adad26271 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 2 Sep 2018 10:56:20 +0200 Subject: [PATCH] gobj: handle infinity and NaN when peeking half float values --- panda/src/gobj/texture.I | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index 4abb480348..7d859dbda8 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -2390,8 +2390,13 @@ get_half_float(const unsigned char *&p) { uint32_t t3 = in & 0x7c00; // Exponent t1 <<= 13; // Align mantissa on MSB t2 <<= 16; // Shift sign bit into position - t1 += 0x38000000; // Adjust bias - t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero + if (t3 != 0x7c00) { + t1 += 0x38000000; // Adjust bias + t1 = (t3 == 0 ? 0 : t1); // Denormals-as-zero + } else { + // Infinity / NaN + t1 |= 0x7f800000; + } t1 |= t2; // Re-insert sign bit v.ui = t1; return v.uf;