From fa04c5037150828ad93944c009abe72040ee053a Mon Sep 17 00:00:00 2001 From: Eisenwave Date: Sat, 6 Feb 2021 12:25:37 +0100 Subject: [PATCH] fix uv-triangles with untextured materials causing error --- main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index fd86bdc..6b9b236 100644 --- a/main.cpp +++ b/main.cpp @@ -137,16 +137,23 @@ VoxelMap voxelizeObj(VoxelizationArgs args) } } else if (hasTexCoords) { - const std::string &textureName = materials[static_cast(materialIndex)].diffuse_texname; + const tinyobj::material_t &material = materials[static_cast(materialIndex)]; + const std::string &textureName = material.diffuse_texname; + if (textureName.empty()) { + goto untextured; + } auto location = voxelizer.textures.find(textureName); if (location == voxelizer.textures.end()) { - VXIO_LOG(ERROR, "Face has invalid texture name \"" + textureName + '"'); + VXIO_LOG(ERROR, + "Face with material \"" + material.name + "\" has unloaded texture name \"" + textureName + + '"'); std::exit(1); } triangle.texture = &location->second; triangle.type = TriangleType::TEXTURED; } else { + untextured: Vec3 color{materials[static_cast(materialIndex)].diffuse}; triangle.color = color.cast(); triangle.type = TriangleType::UNTEXTURED;