From 53a8c8e3cd3a8cdc08b554d63cbd230d2e85eeac Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Fri, 30 Aug 2013 19:08:53 -0400 Subject: [PATCH] Fix bug where the defaulted value caused a crash (wtf?) --- PVRTCEncoder/src/Pixel.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/PVRTCEncoder/src/Pixel.cpp b/PVRTCEncoder/src/Pixel.cpp index 1c97a80..0d669ab 100644 --- a/PVRTCEncoder/src/Pixel.cpp +++ b/PVRTCEncoder/src/Pixel.cpp @@ -60,11 +60,17 @@ namespace PVRTCC { void Pixel::FromBits(const uint8 *bits, const uint8 channelDepth[4], uint8 bitOffset) { - memcpy(m_BitDepth, channelDepth, sizeof(m_BitDepth)); + if(channelDepth) { + memcpy(m_BitDepth, channelDepth, sizeof(m_BitDepth)); + } else { + for(int i = 0; i < 4; i++) { + m_BitDepth[i] = 8; + } + } uint32 nBits = bitOffset; for(uint32 i = 0; i < 4; i++) { - nBits += channelDepth[i]; + nBits += m_BitDepth[i]; } const uint32 nBytes = (nBits >> 3) + ((nBits & 0x7) > 0); @@ -80,7 +86,7 @@ namespace PVRTCC { for(int32 i = 3; i >= 0; i--) { uint8 &channel = m_Component[i]; - uint32 depth = channelDepth[i]; + uint32 depth = m_BitDepth[i]; assert(depth <= 8);