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; 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