From c0bfaa12b08b6a3509a2cc2551292dd17c4f75cb Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 18 May 2016 00:44:58 +0200 Subject: [PATCH] Plugins/Assimp: Fix stack corruption Former-commit-id: 8dc0f64ecb15f4f810c40b0a6c9be519d049ad62 --- plugins/Assimp/Plugin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index 1c998e91c..68c443b29 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -206,8 +206,8 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) { aiVector3D position = iMesh->mVertices[j]; aiVector3D normal = iMesh->mNormals[j]; - aiVector3D tangent = iMesh->mTangents[j]; - aiVector3D uv = iMesh->mTextureCoords[0][j]; + aiVector3D tangent = (iMesh->HasTangentsAndBitangents()) ? iMesh->mTangents[j] : aiVector3D(0.f, 1.f, 0.f); + aiVector3D uv = (iMesh->HasTextureCoords(0)) ? iMesh->mTextureCoords[0][j] : aiVector3D(0.f); vertex->position = parameters.scale * Vector3f(position.x, position.y, position.z); vertex->normal.Set(normal.x, normal.y, normal.z); @@ -246,8 +246,8 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) auto ConvertTexture = [&] (aiTextureType aiType, const char* textureKey, const char* wrapKey = nullptr) { aiString path; - aiTextureMapMode mapMode; - if (aiGetMaterialTexture(aiMat, aiType, 0, &path, nullptr, nullptr, nullptr, nullptr, &mapMode, nullptr) == aiReturn_SUCCESS) + aiTextureMapMode mapMode[3]; + if (aiGetMaterialTexture(aiMat, aiType, 0, &path, nullptr, nullptr, nullptr, nullptr, &mapMode[0], nullptr) == aiReturn_SUCCESS) { matData.SetParameter(MaterialData::CustomDefined); matData.SetParameter(textureKey, stream.GetDirectory() + String(path.data, path.length)); @@ -255,7 +255,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) if (wrapKey) { SamplerWrap wrap = SamplerWrap_Default; - switch (mapMode) + switch (mapMode[0]) { case aiTextureMapMode_Clamp: case aiTextureMapMode_Decal: @@ -271,7 +271,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) break; default: - NazaraWarning("Assimp texture map mode 0x" + String::Number(mapMode, 16) + " not handled"); + NazaraWarning("Assimp texture map mode 0x" + String::Number(mapMode[0], 16) + " not handled"); break; }