mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 06:37:27 +02:00
div by zero fixes, detected by address sanitizer
This commit is contained in:
parent
b105248dd7
commit
18d723b6b4
4 changed files with 15 additions and 4 deletions
|
@ -54,6 +54,7 @@ void LODManager::autoAdjustLOD(float batchTime, float engineRunTime, float delta
|
||||||
float renderTime = batchTime + OVERLAY_AND_SWAP_TIME_BUDGET;
|
float renderTime = batchTime + OVERLAY_AND_SWAP_TIME_BUDGET;
|
||||||
float maxTime = glm::max(renderTime, engineRunTime);
|
float maxTime = glm::max(renderTime, engineRunTime);
|
||||||
const float BLEND_TIMESCALE = 0.3f; // sec
|
const float BLEND_TIMESCALE = 0.3f; // sec
|
||||||
|
const float safeDeltaTime = (deltaTime == 0.0f) ? 0.001f : deltaTime;
|
||||||
float blend = BLEND_TIMESCALE / deltaTimeSec;
|
float blend = BLEND_TIMESCALE / deltaTimeSec;
|
||||||
if (blend > 1.0f) {
|
if (blend > 1.0f) {
|
||||||
blend = 1.0f;
|
blend = 1.0f;
|
||||||
|
|
|
@ -38,7 +38,12 @@ static std::mutex rigRegistryMutex;
|
||||||
|
|
||||||
static bool isEqual(const glm::vec3& u, const glm::vec3& v) {
|
static bool isEqual(const glm::vec3& u, const glm::vec3& v) {
|
||||||
const float EPSILON = 0.0001f;
|
const float EPSILON = 0.0001f;
|
||||||
|
float uLen = glm::length(u);
|
||||||
|
if (uLen == 0.0f) {
|
||||||
|
return glm::length(v) <= EPSILON;
|
||||||
|
} else {
|
||||||
return glm::length(u - v) / glm::length(u) <= EPSILON;
|
return glm::length(u - v) / glm::length(u) <= EPSILON;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isEqual(const glm::quat& p, const glm::quat& q) {
|
static bool isEqual(const glm::quat& p, const glm::quat& q) {
|
||||||
|
|
|
@ -446,7 +446,8 @@ void Avatar::applyPositionDelta(const glm::vec3& delta) {
|
||||||
void Avatar::measureMotionDerivatives(float deltaTime) {
|
void Avatar::measureMotionDerivatives(float deltaTime) {
|
||||||
PerformanceTimer perfTimer("derivatives");
|
PerformanceTimer perfTimer("derivatives");
|
||||||
// linear
|
// 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
|
// Floating point error prevents us from computing velocity in a naive way
|
||||||
// (e.g. vel = (pos - oldPos) / dt) so instead we use _positionOffsetAccumulator.
|
// (e.g. vel = (pos - oldPos) / dt) so instead we use _positionOffsetAccumulator.
|
||||||
glm::vec3 velocity = _positionDeltaAccumulator * invDeltaTime;
|
glm::vec3 velocity = _positionDeltaAccumulator * invDeltaTime;
|
||||||
|
|
|
@ -59,8 +59,12 @@ public:
|
||||||
_max = other._max;
|
_max = other._max;
|
||||||
}
|
}
|
||||||
double totalSamples = _samples + other._samples;
|
double totalSamples = _samples + other._samples;
|
||||||
|
if (totalSamples > 0) {
|
||||||
_average = _average * ((double)_samples / totalSamples)
|
_average = _average * ((double)_samples / totalSamples)
|
||||||
+ other._average * ((double)other._samples / totalSamples);
|
+ other._average * ((double)other._samples / totalSamples);
|
||||||
|
} else {
|
||||||
|
_average = 0.0f;
|
||||||
|
}
|
||||||
_samples += other._samples;
|
_samples += other._samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue