Protect against division by zero in QuadTreeBuilder
This could only happen when there's one leaf in the tree, or all the objects happen to have the same position. Noticed by Csaba Halaz
This commit is contained in:
parent
db8f7f21e8
commit
1a8fd62680
@ -80,10 +80,14 @@ public:
|
||||
{
|
||||
using namespace osg;
|
||||
const Vec3 center(_getLocalCoords(obj));
|
||||
int x = (int)(_dimension * (center.x() - _min.x())
|
||||
int x = 0;
|
||||
if (_max.x() != _min.x())
|
||||
x = (int)(_dimension * (center.x() - _min.x())
|
||||
/ (_max.x() - _min.x()));
|
||||
x = clampTo(x, 0, (_dimension - 1));
|
||||
int y = (int)(_dimension * (center.y() - _min.y())
|
||||
int y = 0;
|
||||
if (_max.y() != _min.y())
|
||||
y = (int)(_dimension * (center.y() - _min.y())
|
||||
/ (_max.y() - _min.y()));
|
||||
y = clampTo(y, 0, (_dimension -1));
|
||||
_addLeafObject(_leaves(y, x), obj);
|
||||
|
Loading…
Reference in New Issue
Block a user