Produce an error and return when indices and data dont match.
This commit is contained in:
@@ -1789,6 +1789,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
unsigned int current_smoothing_id =
|
||||
0; // Initial value. 0 means no smoothing.
|
||||
|
||||
int greatest_vertex_index = -1;
|
||||
int greatest_normal_index = -1;
|
||||
int greatest_texcoord_index = -1;
|
||||
|
||||
shape_t shape;
|
||||
|
||||
size_t line_num = 0;
|
||||
@@ -1907,6 +1911,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
return false;
|
||||
}
|
||||
|
||||
greatest_vertex_index = std::max(greatest_vertex_index, vi.v_idx);
|
||||
greatest_normal_index = std::max(greatest_normal_index, vi.vn_idx);
|
||||
greatest_texcoord_index = std::max(greatest_texcoord_index, vi.vt_idx);
|
||||
|
||||
face.vertex_indices.push_back(vi);
|
||||
size_t n = strspn(token, " \t\r");
|
||||
token += n;
|
||||
@@ -2153,6 +2161,18 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
|
||||
// Ignore unknown command.
|
||||
}
|
||||
|
||||
if (greatest_vertex_index >= v.size()
|
||||
|| greatest_normal_index >= vn.size()
|
||||
|| greatest_texcoord_index >= vt.size())
|
||||
{
|
||||
if (err) {
|
||||
std::stringstream ss;
|
||||
ss << "WARN: Indices do not match the data.\n" << std::endl;
|
||||
(*err) += ss.str();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material,
|
||||
name, triangulate, v);
|
||||
// exportGroupsToShape return false when `usemtl` is called in the last
|
||||
|
||||
Reference in New Issue
Block a user