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&`.
This commit is contained in:
@@ -1441,6 +1441,7 @@ bool LoadObjWithCallback(void *user_data, const callback_t &callback,
|
|||||||
|
|
||||||
// load mtl
|
// load mtl
|
||||||
if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) {
|
if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) {
|
||||||
|
if (readMatFn) {
|
||||||
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
char namebuf[TINYOBJ_SSCANF_BUFFER_SIZE];
|
||||||
token += 7;
|
token += 7;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -1464,6 +1465,7 @@ bool LoadObjWithCallback(void *user_data, const callback_t &callback,
|
|||||||
callback.mtllib_cb(user_data, &materials.at(0),
|
callback.mtllib_cb(user_data, &materials.at(0),
|
||||||
static_cast<int>(materials.size()));
|
static_cast<int>(materials.size()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user