From eba327b9c0dc9516c733db4eb47f1b16428753f8 Mon Sep 17 00:00:00 2001 From: Max Limper Date: Mon, 9 Jul 2018 12:19:33 +0200 Subject: [PATCH 1/2] make tester fail for issue 177 failing (explicit MTL base dir given by API user) --- tests/tester.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/tester.cc b/tests/tester.cc index 82748fa..638507d 100644 --- a/tests/tester.cc +++ b/tests/tester.cc @@ -768,14 +768,20 @@ TEST_CASE("invalid-face-definition", "[face]") { REQUIRE(0 == shapes[0].mesh.indices.size()); } -TEST_CASE("Empty mtl basedir", "[Issue177]") { - // Win32 spesific? +TEST_CASE("Empty mtl basedir", "[Issue177]") { tinyobj::attrib_t attrib; std::vector shapes; std::vector materials; - + std::string err; - bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "issue-177.obj"); + + // A case where the user explicitly provides an empty string + // Win32 specific? + const char * userBaseDir = ""; + bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "issue-177.obj", userBaseDir); + + // if mtl loading fails, we get an error message (WARN) here + ret &= err.empty(); if (!err.empty()) { std::cerr << "[Issue177] " << err << std::endl; From c4e7e65acb76dae671fd0e51a7742aeaf7ed9161 Mon Sep 17 00:00:00 2001 From: Max Limper Date: Mon, 9 Jul 2018 12:21:46 +0200 Subject: [PATCH 2/2] fixed #177 (explicit empty mtl base dir given) --- tiny_obj_loader.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index 9e43a7d..7b9f342 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -1736,9 +1736,8 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, return false; } - std::string baseDir; - if (mtl_basedir) { - baseDir = mtl_basedir; + std::string baseDir = mtl_basedir ? mtl_basedir : ""; + if (!baseDir.empty()) { #ifndef _WIN32 const char dirsep = '/'; #else