From df1669d07e94fd3a8a94f7b36e0987097cc06ce2 Mon Sep 17 00:00:00 2001 From: Minmin Gong Date: Sat, 20 Oct 2018 17:00:27 -0700 Subject: [PATCH] Fix the wrong results when calling aiGetMaterialInteger on bool type properties, such as AI_MATKEY_TWOSIDED. --- code/MaterialSystem.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/code/MaterialSystem.cpp b/code/MaterialSystem.cpp index fa8fb819c..e9ca475fb 100644 --- a/code/MaterialSystem.cpp +++ b/code/MaterialSystem.cpp @@ -194,12 +194,18 @@ aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat, // data is given in ints, simply copy it unsigned int iWrite = 0; if( aiPTI_Integer == prop->mType || aiPTI_Buffer == prop->mType) { - iWrite = prop->mDataLength / sizeof(int32_t); + iWrite = std::max(static_cast(prop->mDataLength / sizeof(int32_t)), 1u); if (pMax) { - iWrite = std::min(*pMax,iWrite); ; + iWrite = std::min(*pMax,iWrite); } - for (unsigned int a = 0; a < iWrite;++a) { - pOut[a] = static_cast(reinterpret_cast(prop->mData)[a]); + if (1 == prop->mDataLength) { + // bool type, 1 byte + *pOut = static_cast(*prop->mData); + } + else { + for (unsigned int a = 0; a < iWrite;++a) { + pOut[a] = static_cast(reinterpret_cast(prop->mData)[a]); + } } if (pMax) { *pMax = iWrite;