Fixed integer overflow occurring in fillChunk() if mesh had a single face with wedge texcoords

This commit is contained in:
Andrea Maggiordomo 2019-04-08 14:03:47 +02:00
parent 011764d5b2
commit 60ea359ec4
1 changed files with 11 additions and 14 deletions

View File

@ -2114,28 +2114,25 @@ namespace vcg
void fillchunkMap() void fillchunkMap()
{ {
if (!vcg::tri::HasPerWedgeTexCoord(_mesh))
return;
_chunkmap.clear(); _chunkmap.clear();
if (!vcg::tri::HasPerWedgeTexCoord(_mesh) || _mesh.face.size() == 0)
return;
typename MESH_TYPE::FaceIterator infrange = _mesh.face.begin(); typename MESH_TYPE::FaceIterator infrange = _mesh.face.begin();
short texind = std::numeric_limits<short>::max(); short texind = _mesh.face[0].WT(0).N();
int hh = 0;
for (typename MESH_TYPE::FaceIterator fit = _mesh.face.begin(); fit != _mesh.face.end(); ++fit) for (typename MESH_TYPE::FaceIterator fit = _mesh.face.begin(); fit != _mesh.face.end(); ++fit)
{ {
if (fit->WT(0).N() != texind) bool last = (fit == (_mesh.face.end() - 1));
if (fit->WT(0).N() != texind || last)
{ {
if ((texind != std::numeric_limits<short>::max()) || (fit == _mesh.face.end() - 1)) int lowind = std::distance(_mesh.face.begin(), infrange);
{ int topind = std::distance(_mesh.face.begin(), fit) - 1;
GLuint lowind = std::distance(_mesh.face.begin(), infrange); if (last)
GLuint topind = std::distance(_mesh.face.begin(), fit) - 1; topind++;
_chunkmap[texind].push_back(std::make_pair(lowind, topind)); _chunkmap[texind].push_back(std::make_pair((GLuint)lowind, (GLuint)topind));
infrange = fit; infrange = fit;
}
texind = fit->WT(0).N(); texind = fit->WT(0).N();
} }
++hh;
} }
_chunkmap[texind].push_back(std::make_pair(std::distance(_mesh.face.begin(), infrange), std::distance(_mesh.face.begin(), _mesh.face.end() - 1)));
} }
void debug(const InternalRendAtts& tobeallocated, const InternalRendAtts& tobedeallocated, const InternalRendAtts& tobeupdated) void debug(const InternalRendAtts& tobeallocated, const InternalRendAtts& tobedeallocated, const InternalRendAtts& tobeupdated)