From bddc374b5af269098d34eb226738d2104df9b77f Mon Sep 17 00:00:00 2001 From: Elijah Nicol Date: Thu, 5 Dec 2024 21:10:46 +1100 Subject: [PATCH] Validate mesh in WriteMesh before AttributeBegin call (#5884) If mesh is validated after AttributeBegin call, then the AttributeBegin is never closed with an AttributeEnd, causing problems in pbrt. Co-authored-by: Kim Kulling --- code/Pbrt/PbrtExporter.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index 907e9a6a2..d5d805868 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -800,10 +800,20 @@ void PbrtExporter::WriteLights() { void PbrtExporter::WriteMesh(aiMesh* mesh) { mOutput << "# - Mesh: "; + const char* mName; if (mesh->mName == aiString("")) - mOutput << "\n"; + mName = ""; else - mOutput << mesh->mName.C_Str() << "\n"; + mName = mesh->mName.C_Str(); + mOutput << mName << "\n"; + + // Check if any types other than tri + if ( (mesh->mPrimitiveTypes & aiPrimitiveType_POINT) + || (mesh->mPrimitiveTypes & aiPrimitiveType_LINE) + || (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) { + std::cerr << "Error: ignoring point / line / polygon mesh " << mName << ".\n"; + return; + } mOutput << "AttributeBegin\n"; aiMaterial* material = mScene->mMaterials[mesh->mMaterialIndex]; @@ -816,14 +826,6 @@ void PbrtExporter::WriteMesh(aiMesh* mesh) { mOutput << " AreaLightSource \"diffuse\" \"rgb L\" [ " << emission.r << " " << emission.g << " " << emission.b << " ]\n"; - // Check if any types other than tri - if ( (mesh->mPrimitiveTypes & aiPrimitiveType_POINT) - || (mesh->mPrimitiveTypes & aiPrimitiveType_LINE) - || (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) { - std::cerr << "Error: ignoring point / line / polygon mesh " << mesh->mName.C_Str() << ".\n"; - return; - } - // Alpha mask std::string alpha; aiString opacityTexture;