Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9347887

Browse files
committed
Show line number for some warning and error message.
1 parent e07a835 commit 9347887

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

loader_example.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static bool TestStreamLoadObj() {
385385
std::string* err) {
386386
(void)err;
387387
(void)matId;
388-
LoadMtl(matMap, materials, &m_matSStream, warn);
388+
LoadMtl(matMap, materials, &m_matSStream, warn, err);
389389

390390
return true;
391391
}

tiny_obj_loader.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,11 @@ void LoadMtl(std::map<std::string, int> *material_map,
13251325

13261326
std::stringstream warn_ss;
13271327

1328+
size_t line_no = 0;
13281329
std::string linebuf;
13291330
while (inStream->peek() != -1) {
13301331
safeGetline(*inStream, linebuf);
1332+
line_no++;
13311333

13321334
// Trim trailing whitespace.
13331335
if (linebuf.size() > 0) {
@@ -1467,7 +1469,8 @@ void LoadMtl(std::map<std::string, int> *material_map,
14671469

14681470
if (has_tr) {
14691471
warn_ss << "Both `d` and `Tr` parameters defined for \""
1470-
<< material.name << "\". Use the value of `d` for dissolve."
1472+
<< material.name << "\". Use the value of `d` for dissolve (line "
1473+
<< line_no << " in .mtl.)"
14711474
<< std::endl;
14721475
}
14731476
has_d = true;
@@ -1478,7 +1481,8 @@ void LoadMtl(std::map<std::string, int> *material_map,
14781481
if (has_d) {
14791482
// `d` wins. Ignore `Tr` value.
14801483
warn_ss << "Both `d` and `Tr` parameters defined for \""
1481-
<< material.name << "\". Use the value of `d` for dissolve."
1484+
<< material.name << "\". Use the value of `d` for dissolve (line "
1485+
<< line_no << " in .mtl.)"
14821486
<< std::endl;
14831487
} else {
14841488
// We invert value of Tr(assume Tr is in range [0, 1])
@@ -1929,7 +1933,9 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
19291933
static_cast<int>(vn.size() / 3),
19301934
static_cast<int>(vt.size() / 2), &vi)) {
19311935
if (err) {
1932-
(*err) = "Failed parse `f' line(e.g. zero value for face index).\n";
1936+
std::stringstream ss;
1937+
ss << "Failed parse `f' line(e.g. zero value for face index. line " << line_num << ".)\n";
1938+
(*err) += ss.str();
19331939
}
19341940
return false;
19351941
}
@@ -1988,9 +1994,11 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
19881994

19891995
if (filenames.empty()) {
19901996
if (warn) {
1991-
(*warn) +=
1992-
"Looks like empty filename for mtllib. Use default "
1993-
"material. \n";
1997+
std::stringstream ss;
1998+
ss << "Looks like empty filename for mtllib. Use default "
1999+
"material (line " << line_num << ".)\n";
2000+
2001+
(*warn) += ss.str();
19942002
}
19952003
} else {
19962004
bool found = false;
@@ -2197,21 +2205,21 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
21972205
if (greatest_v_idx >= static_cast<int>(v.size() / 3)) {
21982206
if (warn) {
21992207
std::stringstream ss;
2200-
ss << "Vertex indices out of bounds.\n" << std::endl;
2208+
ss << "Vertex indices out of bounds (line " << line_num << ".)\n" << std::endl;
22012209
(*warn) += ss.str();
22022210
}
22032211
}
22042212
if (greatest_vn_idx >= static_cast<int>(vn.size() / 3)) {
22052213
if (warn) {
22062214
std::stringstream ss;
2207-
ss << "Vertex normal indices out of bounds.\n" << std::endl;
2215+
ss << "Vertex normal indices out of bounds (line " << line_num << ".)\n" << std::endl;
22082216
(*warn) += ss.str();
22092217
}
22102218
}
22112219
if (greatest_vt_idx >= static_cast<int>(vt.size() / 2)) {
22122220
if (warn) {
22132221
std::stringstream ss;
2214-
ss << "Vertex texcoord indices out of bounds.\n" << std::endl;
2222+
ss << "Vertex texcoord indices out of bounds (line " << line_num << ".)\n" << std::endl;
22152223
(*warn) += ss.str();
22162224
}
22172225
}

0 commit comments

Comments
 (0)