check for 0 properties before copy them

pull/1580/head
Kim Kulling 2017-11-19 19:05:51 +01:00
parent 9707fde709
commit 2a9f79f958
2 changed files with 16 additions and 18 deletions

View File

@ -107,8 +107,9 @@ void SceneCombiner::AddNodePrefixes(aiNode* node, const char* prefix, unsigned i
PrefixString(node->mName,prefix,len); PrefixString(node->mName,prefix,len);
// Process all children recursively // Process all children recursively
for (unsigned int i = 0; i < node->mNumChildren;++i) for ( unsigned int i = 0; i < node->mNumChildren; ++i ) {
AddNodePrefixes(node->mChildren[i],prefix,len); AddNodePrefixes( node->mChildren[ i ], prefix, len );
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -118,7 +119,6 @@ bool SceneCombiner::FindNameMatch(const aiString& name, std::vector<SceneHelper>
// Check whether we find a positive match in one of the given sets // Check whether we find a positive match in one of the given sets
for (unsigned int i = 0; i < input.size(); ++i) { for (unsigned int i = 0; i < input.size(); ++i) {
if (cur != i && input[i].hashes.find(hash) != input[i].hashes.end()) { if (cur != i && input[i].hashes.find(hash) != input[i].hashes.end()) {
return true; return true;
} }
@ -135,7 +135,6 @@ void SceneCombiner::AddNodePrefixesChecked(aiNode* node, const char* prefix, uns
// Check whether we find a positive match in one of the given sets // Check whether we find a positive match in one of the given sets
for (unsigned int i = 0; i < input.size(); ++i) { for (unsigned int i = 0; i < input.size(); ++i) {
if (cur != i && input[i].hashes.find(hash) != input[i].hashes.end()) { if (cur != i && input[i].hashes.find(hash) != input[i].hashes.end()) {
PrefixString(node->mName,prefix,len); PrefixString(node->mName,prefix,len);
break; break;
@ -149,28 +148,25 @@ void SceneCombiner::AddNodePrefixesChecked(aiNode* node, const char* prefix, uns
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Add an offset to all mesh indices in a node graph // Add an offset to all mesh indices in a node graph
void SceneCombiner::OffsetNodeMeshIndices (aiNode* node, unsigned int offset) void SceneCombiner::OffsetNodeMeshIndices (aiNode* node, unsigned int offset) {
{
for (unsigned int i = 0; i < node->mNumMeshes;++i) for (unsigned int i = 0; i < node->mNumMeshes;++i)
node->mMeshes[i] += offset; node->mMeshes[i] += offset;
for (unsigned int i = 0; i < node->mNumChildren;++i) for ( unsigned int i = 0; i < node->mNumChildren; ++i ) {
OffsetNodeMeshIndices(node->mChildren[i],offset); OffsetNodeMeshIndices( node->mChildren[ i ], offset );
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Merges two scenes. Currently only used by the LWS loader. // Merges two scenes. Currently only used by the LWS loader.
void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src, void SceneCombiner::MergeScenes(aiScene** _dest,std::vector<aiScene*>& src, unsigned int flags) {
unsigned int flags) {
if ( nullptr == _dest ) { if ( nullptr == _dest ) {
return; return;
} }
// if _dest points to NULL allocate a new scene. Otherwise clear the old and reuse it // if _dest points to NULL allocate a new scene. Otherwise clear the old and reuse it
if (src.empty()) if (src.empty()) {
{ if (*_dest) {
if (*_dest)
{
(*_dest)->~aiScene(); (*_dest)->~aiScene();
SceneCombiner::CopySceneFlat(_dest,src[0]); SceneCombiner::CopySceneFlat(_dest,src[0]);
} }
@ -1078,8 +1074,7 @@ void SceneCombiner::Copy( aiMesh** _dest, const aiMesh* src ) {
// make a deep copy of all faces // make a deep copy of all faces
GetArrayCopy(dest->mFaces,dest->mNumFaces); GetArrayCopy(dest->mFaces,dest->mNumFaces);
for (unsigned int i = 0; i < dest->mNumFaces;++i) for (unsigned int i = 0; i < dest->mNumFaces;++i) {
{
aiFace& f = dest->mFaces[i]; aiFace& f = dest->mFaces[i];
GetArrayCopy(f.mIndices,f.mNumIndices); GetArrayCopy(f.mIndices,f.mNumIndices);
} }
@ -1091,7 +1086,6 @@ void SceneCombiner::Copy (aiMaterial** _dest, const aiMaterial* src) {
return; return;
} }
aiMaterial* dest = (aiMaterial*) ( *_dest = new aiMaterial() ); aiMaterial* dest = (aiMaterial*) ( *_dest = new aiMaterial() );
dest->Clear(); dest->Clear();
@ -1248,6 +1242,10 @@ void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src) {
return; return;
} }
if ( 0 == src->mNumProperties ) {
return;
}
aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties ); aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties );
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys); std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);

View File

@ -187,7 +187,7 @@ struct aiMetadata {
static inline static inline
aiMetadata *Alloc( unsigned int numProperties ) { aiMetadata *Alloc( unsigned int numProperties ) {
if ( 0 == numProperties ) { if ( 0 == numProperties ) {
return NULL; return nullptr;
} }
aiMetadata *data = new aiMetadata; aiMetadata *data = new aiMetadata;