mirror of
https://github.com/lubosz/overte.git
synced 2025-04-25 01:03:59 +02:00
Merge pull request #11566 from hyperlogic/bug-fix/div-by-zero
div by zero fixes, detected by address sanitizer
This commit is contained in:
commit
469b68011c
4 changed files with 18 additions and 5 deletions
|
@ -54,7 +54,9 @@ 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
|
||||
float blend = BLEND_TIMESCALE / deltaTimeSec;
|
||||
const float MIN_DELTA_TIME = 0.001f;
|
||||
const float safeDeltaTime = glm::max(deltaTimeSec, MIN_DELTA_TIME);
|
||||
float blend = BLEND_TIMESCALE / safeDeltaTime;
|
||||
if (blend > 1.0f) {
|
||||
blend = 1.0f;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,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) / uLen) <= EPSILON;
|
||||
}
|
||||
}
|
||||
|
||||
static bool isEqual(const glm::quat& p, const glm::quat& q) {
|
||||
|
|
|
@ -453,7 +453,9 @@ void Avatar::applyPositionDelta(const glm::vec3& delta) {
|
|||
void Avatar::measureMotionDerivatives(float deltaTime) {
|
||||
PerformanceTimer perfTimer("derivatives");
|
||||
// linear
|
||||
float invDeltaTime = 1.0f / deltaTime;
|
||||
const float MIN_DELTA_TIME = 0.001f;
|
||||
const float safeDeltaTime = glm::max(deltaTime, MIN_DELTA_TIME);
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue