From 58ce3ee8791dd9bc356c0914f93ac816eb2e0eb3 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Thu, 3 Feb 2011 13:22:38 +0000 Subject: [PATCH] # fix potential LWO crashbug related to UV processing [http://sourceforge.net/projects/assimp/forums/forum/817653/topic/4070109] git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@899 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/LWOLoader.cpp | 4 +++- code/LWOMaterial.cpp | 11 +++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/code/LWOLoader.cpp b/code/LWOLoader.cpp index 320c29630..55ffb49ef 100644 --- a/code/LWOLoader.cpp +++ b/code/LWOLoader.cpp @@ -294,7 +294,9 @@ void LWOImporter::InternReadFile( const std::string& pFile, aiColor4D* pvVC[AI_MAX_NUMBER_OF_COLOR_SETS]; for (unsigned int mui = 0; mui < AI_MAX_NUMBER_OF_COLOR_SETS;++mui) { - if (0xffffffff == vVColorIndices[mui])break; + if (0xffffffff == vVColorIndices[mui]) { + break; + } pvVC[mui] = mesh->mColors[mui] = new aiColor4D[mesh->mNumVertices]; } diff --git a/code/LWOMaterial.cpp b/code/LWOMaterial.cpp index cf76dc564..861524ff4 100644 --- a/code/LWOMaterial.cpp +++ b/code/LWOMaterial.cpp @@ -425,7 +425,7 @@ void LWOImporter::FindUVChannels(LWO::Surface& surf, if (uv.abAssigned[idx] && ((aiVector2D*)&uv.rawData[0])[idx] != aiVector2D()) { - if (next >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { + if (extra >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { DefaultLogger::get()->error("LWO: Maximum number of UV channels for " "this mesh reached. Skipping channel \'" + uv.name + "\'"); @@ -442,9 +442,9 @@ void LWOImporter::FindUVChannels(LWO::Surface& surf, had |= FindUVChannels(surf.mBumpTextures,layer,uv,next); had |= FindUVChannels(surf.mReflectionTextures,layer,uv,next); + // We have a texture referencing this UV channel so we have to take special care + // and are willing to drop unreferenced channels in favour of it. if (had != 0) { - - // We have a texture referencing this UV channel so we have to take special care of it if (num_extra) { for (unsigned int a = next; a < std::min( extra, AI_MAX_NUMBER_OF_TEXTURECOORDS-1u ); ++a) { @@ -454,9 +454,8 @@ void LWOImporter::FindUVChannels(LWO::Surface& surf, ++extra; out[next++] = i; } + // Bäh ... seems not to be used at all. Push to end if enough space is available. else { - - // Bäh ... seems not to be used at all. Push to end if enough space is available. out[extra++] = i; ++num_extra; } @@ -467,7 +466,7 @@ void LWOImporter::FindUVChannels(LWO::Surface& surf, } } } - if (next != AI_MAX_NUMBER_OF_TEXTURECOORDS) { + if (extra < AI_MAX_NUMBER_OF_TEXTURECOORDS) { out[extra] = 0xffffffff; } }