[Cg1] obj.cpp: `loadOBJ` wrongly handles negative vertex index

Wentao Liu s8weliuu at stud.uni-saarland.de
Tue Jan 14 13:42:34 CET 2020

There is a bug in function `loadOBJ` when reading face element of  
negative vertex index:

     if (v[0].vidx<0) v[0].vidx = vertices.size() - v[0].vidx; else  

when  `v[0].vidx` is negative, `vertices.size() - v[0].vidx` return an  
index larger then `vertices.size()`, which certainly causes  
out-of-boundary exception.

Changing plus to minus could work:
     if (v[0].vidx<0) v[0].vidx = vertices.size() + v[0].vidx; else  

Fix: do the same for `v[*].vidx`, ` v[*].tidx`, `v[*].nidx`, and  
change the definition of vidx, tidx, nidx from
     size_t vidx, tidx, nidx;
     long int vidx, tidx, nidx;

Or simply apply the patch attached.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_loadOBJ.patch
Type: text/x-diff
Size: 3193 bytes
Desc: not available
URL: <http://mail.cg.uni-saarland.de/pipermail/cg1/attachments/20200114/73f70e74/attachment.bin>

More information about the Cg1 mailing list