Fix unitialized memory in nurbsVertex, prevent division by zero in NurbsCurveEvaluator

This commit is contained in:
tobspr 2015-12-09 20:46:19 +01:00 committed by rdb
parent c2b44b57c9
commit 8e772366b1
2 changed files with 8 additions and 2 deletions

View File

@ -244,8 +244,13 @@ get_vertices(NurbsCurveEvaluator::Vert3Array &verts, const NodePath &rel_to) con
int vi;
for (vi = 0; vi < num_vertices; vi++) {
LVecBase4 vertex = get_vertex(vi, rel_to);
LPoint3 v3(vertex[0] / vertex[3], vertex[1] / vertex[3], vertex[2] / vertex[3]);
verts.push_back(v3);
// Avoid division by zero
if (vertex[3] == 0.0) {
verts.push_back(LPoint3(vertex[0], vertex[1], vertex[2]));
} else {
LPoint3 v3(vertex[0] / vertex[3], vertex[1] / vertex[3], vertex[2] / vertex[3]);
verts.push_back(v3);
}
}
}

View File

@ -20,6 +20,7 @@
////////////////////////////////////////////////////////////////////
INLINE NurbsVertex::
NurbsVertex() {
_vertex.set(0, 0, 0, 1);
}
////////////////////////////////////////////////////////////////////