Merge pull request #6902 from sethalves/no-nan

check values in location updates for NaN before using them
This commit is contained in:
Brad Hefta-Gaub 2016-01-22 13:34:15 -08:00
commit 9ec2cf1ab9
8 changed files with 69 additions and 2 deletions

View file

@ -478,3 +478,7 @@ AACube& AACube::operator += (const glm::vec3& point) {
return (*this);
}
bool AACube::containsNaN() const {
return isNaN(_corner) || isNaN(_scale);
}

View file

@ -66,6 +66,8 @@ public:
AACube& operator += (const glm::vec3& point);
bool containsNaN() const;
private:
glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const;
glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const;

View file

@ -425,3 +425,10 @@ void generateBasisVectors(const glm::vec3& primaryAxis, const glm::vec3& seconda
vAxisOut = glm::cross(wAxisOut, uAxisOut);
}
bool isNaN(glm::vec3 value) {
return isNaN(value.x) || isNaN(value.y) || isNaN(value.z);
}
bool isNaN(glm::quat value) {
return isNaN(value.w) || isNaN(value.x) || isNaN(value.y) || isNaN(value.z);
}

View file

@ -224,4 +224,8 @@ glm::vec3 transformVector(const glm::mat4& m, const glm::vec3& v);
void generateBasisVectors(const glm::vec3& primaryAxis, const glm::vec3& secondaryAxis,
glm::vec3& uAxisOut, glm::vec3& vAxisOut, glm::vec3& wAxisOut);
bool isNaN(glm::vec3 value);
bool isNaN(glm::quat value);
#endif // hifi_GLMHelpers_h

View file

@ -624,8 +624,8 @@ void debug::checkDeadBeef(void* memoryVoid, int size) {
assert(memcmp((unsigned char*)memoryVoid, DEADBEEF, std::min(size, DEADBEEF_SIZE)) != 0);
}
bool isNaN(float value) {
return value != value;
bool isNaN(float value) {
return value != value;
}
QString formatUsecTime(float usecs, int prec) {

View file

@ -314,6 +314,11 @@ glm::vec3 SpatiallyNestable::getPosition(int jointIndex, bool& success) const {
}
void SpatiallyNestable::setPosition(const glm::vec3& position, bool& success) {
// guard against introducing NaN into the transform
if (isNaN(position)) {
success = false;
return;
}
Transform parentTransform = getParentTransform(success);
Transform myWorldTransform;
_transformLock.withWriteLock([&] {
@ -358,6 +363,12 @@ glm::quat SpatiallyNestable::getOrientation(int jointIndex, bool& success) const
}
void SpatiallyNestable::setOrientation(const glm::quat& orientation, bool& success) {
// guard against introducing NaN into the transform
if (isNaN(orientation)) {
success = false;
return;
}
Transform parentTransform = getParentTransform(success);
Transform myWorldTransform;
_transformLock.withWriteLock([&] {
@ -408,6 +419,10 @@ const Transform SpatiallyNestable::getTransform(int jointIndex, bool& success) c
}
void SpatiallyNestable::setTransform(const Transform& transform, bool& success) {
if (transform.containsNaN()) {
success = false;
return;
}
Transform parentTransform = getParentTransform(success);
_transformLock.withWriteLock([&] {
Transform::inverseMult(_transform, parentTransform, transform);
@ -432,6 +447,11 @@ glm::vec3 SpatiallyNestable::getScale(int jointIndex) const {
}
void SpatiallyNestable::setScale(const glm::vec3& scale) {
// guard against introducing NaN into the transform
if (isNaN(scale)) {
qDebug() << "SpatiallyNestable::setLocalScale -- scale contains NaN";
return;
}
// TODO: scale
_transformLock.withWriteLock([&] {
_transform.setScale(scale);
@ -448,6 +468,11 @@ const Transform SpatiallyNestable::getLocalTransform() const {
}
void SpatiallyNestable::setLocalTransform(const Transform& transform) {
// guard against introducing NaN into the transform
if (transform.containsNaN()) {
qDebug() << "SpatiallyNestable::setLocalTransform -- transform contains NaN";
return;
}
_transformLock.withWriteLock([&] {
_transform = transform;
});
@ -463,6 +488,11 @@ glm::vec3 SpatiallyNestable::getLocalPosition() const {
}
void SpatiallyNestable::setLocalPosition(const glm::vec3& position) {
// guard against introducing NaN into the transform
if (isNaN(position)) {
qDebug() << "SpatiallyNestable::setLocalPosition -- position contains NaN";
return;
}
_transformLock.withWriteLock([&] {
_transform.setTranslation(position);
});
@ -478,6 +508,11 @@ glm::quat SpatiallyNestable::getLocalOrientation() const {
}
void SpatiallyNestable::setLocalOrientation(const glm::quat& orientation) {
// guard against introducing NaN into the transform
if (isNaN(orientation)) {
qDebug() << "SpatiallyNestable::setLocalOrientation -- orientation contains NaN";
return;
}
_transformLock.withWriteLock([&] {
_transform.setRotation(orientation);
});
@ -494,6 +529,11 @@ glm::vec3 SpatiallyNestable::getLocalScale() const {
}
void SpatiallyNestable::setLocalScale(const glm::vec3& scale) {
// guard against introducing NaN into the transform
if (isNaN(scale)) {
qDebug() << "SpatiallyNestable::setLocalScale -- scale contains NaN";
return;
}
// TODO: scale
_transformLock.withWriteLock([&] {
_transform.setScale(scale);
@ -561,6 +601,10 @@ AACube SpatiallyNestable::getMaximumAACube(bool& success) const {
}
void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) {
if (queryAACube.containsNaN()) {
qDebug() << "SpatiallyNestable::setQueryAACube -- cube contains NaN";
return;
}
_queryAACube = queryAACube;
if (queryAACube.getScale() > 0.0f) {
_queryAACubeSet = true;

View file

@ -150,3 +150,7 @@ QJsonObject Transform::toJson(const Transform& transform) {
}
return result;
}
bool Transform::containsNaN() const {
return isNaN(_rotation) || isNaN(_scale) || isNaN(_translation);
}

View file

@ -145,6 +145,8 @@ public:
Vec4 transform(const Vec4& pos) const;
Vec3 transform(const Vec3& pos) const;
bool containsNaN() const;
protected:
enum Flag {