From 3736a5791f63881b3ebe14fbb593099a7dfe7bc1 Mon Sep 17 00:00:00 2001 From: "Adi Shavit @ MacBookPro" Date: Wed, 27 Jul 2016 10:04:22 +0300 Subject: [PATCH] Fix a crash bug in `LoadObjWithCallback()` when passing a nullptr as `MaterialReader *readMatFn`. - This preserves the existing API. If `nullptr` is passed then the material file will be ignored. This is useful when the user is not interested in the materials. - Note that if `nullptr` is not a valid option for this function, then the API needs to be changed to take `MaterialReader&`. --- tiny_obj_loader.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index 68f0d7d..0e85632 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -1441,6 +1441,7 @@ bool LoadObjWithCallback(void *user_data, const callback_t &callback, // load mtl if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) { + if (readMatFn) { char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE]; token += 7; #ifdef _MSC_VER @@ -1464,6 +1465,7 @@ bool LoadObjWithCallback(void *user_data, const callback_t &callback, callback.mtllib_cb(user_data, &materials.at(0), static_cast(materials.size())); } + } continue; }