MaterialSystem: fix some findings.

pull/1056/head
Kim Kulling 2016-11-03 23:29:03 +01:00
parent c849e0108d
commit dfaea27dfc
1 changed files with 27 additions and 24 deletions

View File

@ -42,8 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Implementation of the material system of the library * @brief Implementation of the material system of the library
*/ */
#include "Hash.h" #include "Hash.h"
#include "fast_atof.h" #include "fast_atof.h"
#include "ParsingUtils.h" #include "ParsingUtils.h"
@ -152,7 +150,8 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
} }
// strings are zero-terminated with a 32 bit length prefix, so this is safe // strings are zero-terminated with a 32 bit length prefix, so this is safe
const char *cur = prop->mData + 4; const char *cur = prop->mData + 4;
ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]); ai_assert( prop->mDataLength >= 5 );
ai_assert( !prop->mData[ prop->mDataLength - 1 ] );
for ( unsigned int a = 0; ;++a) { for ( unsigned int a = 0; ;++a) {
cur = fast_atoreal_move<ai_real>(cur,pOut[a]); cur = fast_atoreal_move<ai_real>(cur,pOut[a]);
if ( a==iWrite-1 ) { if ( a==iWrite-1 ) {
@ -170,7 +169,6 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
} }
} }
return AI_SUCCESS; return AI_SUCCESS;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -225,7 +223,8 @@ aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat,
} }
// strings are zero-terminated with a 32 bit length prefix, so this is safe // strings are zero-terminated with a 32 bit length prefix, so this is safe
const char *cur = prop->mData+4; const char *cur = prop->mData+4;
ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]); ai_assert( prop->mDataLength >= 5 );
ai_assert( !prop->mData[ prop->mDataLength - 1 ] );
for (unsigned int a = 0; ;++a) { for (unsigned int a = 0; ;++a) {
pOut[a] = strtol10(cur,&cur); pOut[a] = strtol10(cur,&cur);
if(a==iWrite-1) { if(a==iWrite-1) {
@ -298,7 +297,8 @@ aiReturn aiGetMaterialString(const aiMaterial* pMat,
// The string is stored as 32 but length prefix followed by zero-terminated UTF8 data // The string is stored as 32 but length prefix followed by zero-terminated UTF8 data
pOut->length = static_cast<unsigned int>(*reinterpret_cast<uint32_t*>(prop->mData)); pOut->length = static_cast<unsigned int>(*reinterpret_cast<uint32_t*>(prop->mData));
ai_assert(pOut->length+1+4==prop->mDataLength && !prop->mData[prop->mDataLength-1]); ai_assert( pOut->length+1+4==prop->mDataLength );
ai_assert( !prop->mData[ prop->mDataLength - 1 ] );
memcpy(pOut->data,prop->mData+4,pOut->length+1); memcpy(pOut->data,prop->mData+4,pOut->length+1);
} }
else { else {
@ -317,7 +317,7 @@ ASSIMP_API unsigned int aiGetMaterialTextureCount(const C_STRUCT aiMaterial* pMa
{ {
ai_assert (pMat != NULL); ai_assert (pMat != NULL);
/* Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again) */ // Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again)
unsigned int max = 0; unsigned int max = 0;
for (unsigned int i = 0; i < pMat->mNumProperties;++i) { for (unsigned int i = 0; i < pMat->mNumProperties;++i) {
aiMaterialProperty* prop = pMat->mProperties[i]; aiMaterialProperty* prop = pMat->mProperties[i];
@ -381,14 +381,17 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat,
return AI_SUCCESS; return AI_SUCCESS;
} }
static const unsigned int DefaultNumAllocated = 5;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Construction. Actually the one and only way to get an aiMaterial instance // Construction. Actually the one and only way to get an aiMaterial instance
aiMaterial::aiMaterial() aiMaterial::aiMaterial()
: mNumProperties( 0 )
, mNumAllocated( DefaultNumAllocated )
, mProperties( NULL )
{ {
// Allocate 5 entries by default // Allocate 5 entries by default
mNumProperties = 0; mProperties = new aiMaterialProperty*[ DefaultNumAllocated ];
mNumAllocated = 5;
mProperties = new aiMaterialProperty*[5];
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -585,8 +588,9 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
} }
} }
if(pcOld) if ( pcOld ) {
delete[] pcOld; delete[] pcOld;
}
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) { for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
aiMaterialProperty* propSrc = pcSrc->mProperties[i]; aiMaterialProperty* propSrc = pcSrc->mProperties[i];
@ -617,5 +621,4 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
prop->mData = new char[propSrc->mDataLength]; prop->mData = new char[propSrc->mDataLength];
memcpy(prop->mData,propSrc->mData,prop->mDataLength); memcpy(prop->mData,propSrc->mData,prop->mDataLength);
} }
return;
} }