mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 00:13:53 +02:00
check values in location updates for NaN before using them
This commit is contained in:
parent
58b7708315
commit
451464cb47
5 changed files with 84 additions and 0 deletions
|
@ -478,3 +478,13 @@ AACube& AACube::operator += (const glm::vec3& point) {
|
|||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
bool AACube::containsNaN() const {
|
||||
if ( _corner.x != _corner.x || _corner.y != _corner.y || _corner.z != _corner.z) {
|
||||
return true;
|
||||
}
|
||||
if (_scale != _scale) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 (position.x != position.x || position.y != position.y || position.z != position.z) {
|
||||
success = false;
|
||||
return;
|
||||
}
|
||||
Transform parentTransform = getParentTransform(success);
|
||||
Transform myWorldTransform;
|
||||
_transformLock.withWriteLock([&] {
|
||||
|
@ -358,6 +363,15 @@ 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 (orientation.x != orientation.x ||
|
||||
orientation.y != orientation.y ||
|
||||
orientation.z != orientation.z ||
|
||||
orientation.w != orientation.w) {
|
||||
success = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Transform parentTransform = getParentTransform(success);
|
||||
Transform myWorldTransform;
|
||||
_transformLock.withWriteLock([&] {
|
||||
|
@ -408,6 +422,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 +450,11 @@ glm::vec3 SpatiallyNestable::getScale(int jointIndex) const {
|
|||
}
|
||||
|
||||
void SpatiallyNestable::setScale(const glm::vec3& scale) {
|
||||
// guard against introducing NaN into the transform
|
||||
if (scale.x != scale.x || scale.y != scale.y || scale.z != scale.z) {
|
||||
qDebug() << "SpatiallyNestable::setLocalScale -- scale contains NaN";
|
||||
return;
|
||||
}
|
||||
// TODO: scale
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setScale(scale);
|
||||
|
@ -448,6 +471,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 +491,11 @@ glm::vec3 SpatiallyNestable::getLocalPosition() const {
|
|||
}
|
||||
|
||||
void SpatiallyNestable::setLocalPosition(const glm::vec3& position) {
|
||||
// guard against introducing NaN into the transform
|
||||
if (position.x != position.x || position.y != position.y || position.z != position.z) {
|
||||
qDebug() << "SpatiallyNestable::setLocalPosition -- position contains NaN";
|
||||
return;
|
||||
}
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setTranslation(position);
|
||||
});
|
||||
|
@ -478,6 +511,14 @@ glm::quat SpatiallyNestable::getLocalOrientation() const {
|
|||
}
|
||||
|
||||
void SpatiallyNestable::setLocalOrientation(const glm::quat& orientation) {
|
||||
// guard against introducing NaN into the transform
|
||||
if (orientation.x != orientation.x ||
|
||||
orientation.y != orientation.y ||
|
||||
orientation.z != orientation.z ||
|
||||
orientation.w != orientation.w) {
|
||||
qDebug() << "SpatiallyNestable::setLocalOrientation -- orientation contains NaN";
|
||||
return;
|
||||
}
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setRotation(orientation);
|
||||
});
|
||||
|
@ -494,6 +535,11 @@ glm::vec3 SpatiallyNestable::getLocalScale() const {
|
|||
}
|
||||
|
||||
void SpatiallyNestable::setLocalScale(const glm::vec3& scale) {
|
||||
// guard against introducing NaN into the transform
|
||||
if (scale.x != scale.x || scale.y != scale.y || scale.z != scale.z) {
|
||||
qDebug() << "SpatiallyNestable::setLocalScale -- scale contains NaN";
|
||||
return;
|
||||
}
|
||||
// TODO: scale
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setScale(scale);
|
||||
|
@ -561,6 +607,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;
|
||||
|
|
|
@ -150,3 +150,23 @@ QJsonObject Transform::toJson(const Transform& transform) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Transform::containsNaN() const {
|
||||
if (_rotation.x != _rotation.x ||
|
||||
_rotation.y != _rotation.y ||
|
||||
_rotation.z != _rotation.z ||
|
||||
_rotation.w != _rotation.w) {
|
||||
return true;
|
||||
}
|
||||
if (_scale.x != _scale.x ||
|
||||
_scale.y != _scale.y ||
|
||||
_scale.z != _scale.z) {
|
||||
return true;
|
||||
}
|
||||
if (_translation.x != _translation.x ||
|
||||
_translation.y != _translation.y ||
|
||||
_translation.z != _translation.z) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -145,6 +145,8 @@ public:
|
|||
Vec4 transform(const Vec4& pos) const;
|
||||
Vec3 transform(const Vec3& pos) const;
|
||||
|
||||
bool containsNaN() const;
|
||||
|
||||
protected:
|
||||
|
||||
enum Flag {
|
||||
|
|
Loading…
Reference in a new issue