Skip to content

Commit b1f594d

Browse files
committed
Merge branch 'master' of github.com:syoyo/tinyobjloader
2 parents 02df494 + 826a892 commit b1f594d

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

experimental/tinyobj_loader_opt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,8 @@ typedef struct {
12381238
// 3. Do parallel parsing for each line.
12391239
// 4. Reconstruct final mesh data structure.
12401240

1241+
// Raise # of max threads if you have more CPU cores...
1242+
// In 2018, 32 cores are getting common in high-end workstaion PC.
12411243
#define kMaxThreads (32)
12421244

12431245
static inline bool is_line_ending(const char *p, size_t i, size_t end_i) {

tiny_obj_loader.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
17891789
unsigned int current_smoothing_id =
17901790
0; // Initial value. 0 means no smoothing.
17911791

1792+
int greatest_v_idx = -1;
1793+
int greatest_vn_idx = -1;
1794+
int greatest_vt_idx = -1;
1795+
17921796
shape_t shape;
17931797

17941798
size_t line_num = 0;
@@ -1907,6 +1911,10 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
19071911
return false;
19081912
}
19091913

1914+
greatest_v_idx = greatest_v_idx > vi.v_idx ? greatest_v_idx : vi.v_idx;
1915+
greatest_vn_idx = greatest_vn_idx > vi.vn_idx ? greatest_vn_idx : vi.vn_idx;
1916+
greatest_vt_idx = greatest_vt_idx > vi.vt_idx ? greatest_vt_idx : vi.vt_idx;
1917+
19101918
face.vertex_indices.push_back(vi);
19111919
size_t n = strspn(token, " \t\r");
19121920
token += n;
@@ -2153,6 +2161,31 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
21532161
// Ignore unknown command.
21542162
}
21552163

2164+
if (greatest_v_idx >= static_cast<int>(v.size() / 3))
2165+
{
2166+
if (err) {
2167+
std::stringstream ss;
2168+
ss << "WARN: Vertex indices out of bounds.\n" << std::endl;
2169+
(*err) += ss.str();
2170+
}
2171+
}
2172+
if (greatest_vn_idx >= static_cast<int>(vn.size() / 3))
2173+
{
2174+
if (err) {
2175+
std::stringstream ss;
2176+
ss << "WARN: Vertex normal indices out of bounds.\n" << std::endl;
2177+
(*err) += ss.str();
2178+
}
2179+
}
2180+
if (greatest_vt_idx >= static_cast<int>(vt.size() / 2))
2181+
{
2182+
if (err) {
2183+
std::stringstream ss;
2184+
ss << "WARN: Vertex texcoord indices out of bounds.\n" << std::endl;
2185+
(*err) += ss.str();
2186+
}
2187+
}
2188+
21562189
bool ret = exportGroupsToShape(&shape, faceGroup, lineGroup, tags, material,
21572190
name, triangulate, v);
21582191
// exportGroupsToShape return false when `usemtl` is called in the last

0 commit comments

Comments
 (0)