div by zero fixes, detected by address sanitizer

This commit is contained in:
Anthony J. Thibault 2017-10-10 16:17:39 -07:00
parent b105248dd7
commit 18d723b6b4
4 changed files with 15 additions and 4 deletions

View file

@ -54,6 +54,7 @@ void LODManager::autoAdjustLOD(float batchTime, float engineRunTime, float delta
float renderTime = batchTime + OVERLAY_AND_SWAP_TIME_BUDGET;
float maxTime = glm::max(renderTime, engineRunTime);
const float BLEND_TIMESCALE = 0.3f; // sec
const float safeDeltaTime = (deltaTime == 0.0f) ? 0.001f : deltaTime;
float blend = BLEND_TIMESCALE / deltaTimeSec;
if (blend > 1.0f) {
blend = 1.0f;

View file

@ -38,7 +38,12 @@ static std::mutex rigRegistryMutex;
static bool isEqual(const glm::vec3& u, const glm::vec3& v) {
const float EPSILON = 0.0001f;
return glm::length(u - v) / glm::length(u) <= EPSILON;
float uLen = glm::length(u);
if (uLen == 0.0f) {
return glm::length(v) <= EPSILON;
} else {
return glm::length(u - v) / glm::length(u) <= EPSILON;
}
}
static bool isEqual(const glm::quat& p, const glm::quat& q) {

View file

@ -446,7 +446,8 @@ void Avatar::applyPositionDelta(const glm::vec3& delta) {
void Avatar::measureMotionDerivatives(float deltaTime) {
PerformanceTimer perfTimer("derivatives");
// linear
float invDeltaTime = 1.0f / deltaTime;
const float safeDeltaTime = (deltaTime == 0.0f) ? 0.001f : deltaTime;
float invDeltaTime = 1.0f / safeDeltaTime;
// Floating point error prevents us from computing velocity in a naive way
// (e.g. vel = (pos - oldPos) / dt) so instead we use _positionOffsetAccumulator.
glm::vec3 velocity = _positionDeltaAccumulator * invDeltaTime;

View file

@ -59,8 +59,12 @@ public:
_max = other._max;
}
double totalSamples = _samples + other._samples;
_average = _average * ((double)_samples / totalSamples)
+ other._average * ((double)other._samples / totalSamples);
if (totalSamples > 0) {
_average = _average * ((double)_samples / totalSamples)
+ other._average * ((double)other._samples / totalSamples);
} else {
_average = 0.0f;
}
_samples += other._samples;
}