diff --git a/code/EmbedTexturesProcess.cpp b/code/EmbedTexturesProcess.cpp index ebe7a0897..a6dd8457e 100644 --- a/code/EmbedTexturesProcess.cpp +++ b/code/EmbedTexturesProcess.cpp @@ -124,22 +124,28 @@ bool EmbedTexturesProcess::addTexture(aiScene* pScene, std::string path) const { file.read(reinterpret_cast(imageContent), imageSize); // Enlarging the textures table - auto textureId = pScene->mNumTextures++; + unsigned int textureId = pScene->mNumTextures++; auto oldTextures = pScene->mTextures; pScene->mTextures = new aiTexture*[pScene->mNumTextures]; - memmove(pScene->mTextures, oldTextures, sizeof(aiTexture*) * (pScene->mNumTextures - 1u)); + ::memmove(pScene->mTextures, oldTextures, sizeof(aiTexture*) * (pScene->mNumTextures - 1u)); // Add the new texture - auto pTexture = new aiTexture(); + auto pTexture = new aiTexture; pTexture->mHeight = 0; // Means that this is still compressed pTexture->mWidth = static_cast(imageSize); pTexture->pcData = imageContent; auto extension = path.substr(path.find_last_of('.') + 1u); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); - if (extension == "jpeg") extension = "jpg"; - strcpy(pTexture->achFormatHint, extension.c_str()); + if (extension == "jpeg") { + extension = "jpg"; + } + size_t len = extension.size(); + if (len > HINTMAXTEXTURELEN -1 ) { + len = HINTMAXTEXTURELEN - 1; + } + ::strncpy(pTexture->achFormatHint, extension.c_str(), len); pScene->mTextures[textureId] = pTexture; return true; diff --git a/code/Q3BSPFileImporter.cpp b/code/Q3BSPFileImporter.cpp index 58fbef985..8b9e3c037 100644 --- a/code/Q3BSPFileImporter.cpp +++ b/code/Q3BSPFileImporter.cpp @@ -400,6 +400,7 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, if (nullptr != m_pCurrentFace) { m_pCurrentFace->mNumIndices = 3; m_pCurrentFace->mIndices = new unsigned int[3]; + m_pCurrentFace->mIndices[ idx ] = vertIdx; } } @@ -409,9 +410,7 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel, pMesh->mTextureCoords[ 0 ][ vertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f ); pMesh->mTextureCoords[ 1 ][ vertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f ); - m_pCurrentFace->mIndices[ idx ] = vertIdx; vertIdx++; - idx++; } } diff --git a/include/assimp/texture.h b/include/assimp/texture.h index 5be7229ec..575f5754f 100644 --- a/include/assimp/texture.h +++ b/include/assimp/texture.h @@ -117,6 +117,8 @@ struct aiTexel #include "./Compiler/poppack1.h" +#define HINTMAXTEXTURELEN 9 + // -------------------------------------------------------------------------------- /** Helper structure to describe an embedded texture * @@ -166,7 +168,7 @@ struct aiTexture { * E.g. 'dds\\0', 'pcx\\0', 'jpg\\0'. All characters are lower-case. * The fourth character will always be '\\0'. */ - char achFormatHint[9];// 8 for string + 1 for terminator. + char achFormatHint[ HINTMAXTEXTURELEN ];// 8 for string + 1 for terminator. /** Data of the texture. *