[Scummvm-git-logs] scummvm master -> ab828f3f3c0fc140c5d6ba730720274a71dbd40a

aquadran aquadran at gmail.com
Tue Dec 8 18:36:04 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ab828f3f3c GRIM: gracefully handle critical floating point operations


Commit: ab828f3f3c0fc140c5d6ba730720274a71dbd40a
    https://github.com/scummvm/scummvm/commit/ab828f3f3c0fc140c5d6ba730720274a71dbd40a
Author: Christian Krause (chkr at plauener.de)
Date: 2020-12-08T19:35:54+01:00

Commit Message:
GRIM: gracefully handle critical floating point operations

Changed paths:
    engines/grim/actor.cpp
    engines/grim/emi/costume/emihead.cpp
    engines/grim/emi/modelemi.cpp
    engines/grim/emi/sound/track.cpp


diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp
index b4258c8237..fe0f2d38b5 100644
--- a/engines/grim/actor.cpp
+++ b/engines/grim/actor.cpp
@@ -1130,7 +1130,8 @@ Math::Angle Actor::getYawTo(const Actor *a) const {
 	} else {
 		delta.z() = 0;
 	}
-
+	if (delta.getMagnitude() < Math::epsilon)
+		return Math::Angle(0);
 	return Math::Vector3d::angle(forwardVec, delta);
 }
 
@@ -2024,13 +2025,18 @@ Math::Vector3d Actor::getTangentPos(const Math::Vector3d &pos, const Math::Vecto
 	if (_collisionMode == CollisionOff) {
 		return dest;
 	}
-
+	if (pos.getDistanceTo(dest) < Math::epsilon) {
+		return dest;
+	}
 	Math::Vector3d p;
 	float size;
 	if (!getSphereInfo(false, size, p))
 		return dest;
 	Math::Vector2d p1(pos.x(), pos.y());
 	Math::Vector2d p2(dest.x(), dest.y());
+	if (p1.getDistanceTo(p2) < Math::epsilon) {
+		return dest;
+	}
 	Math::Segment2d segment(p1, p2);
 
 	// TODO: collision with Box
diff --git a/engines/grim/emi/costume/emihead.cpp b/engines/grim/emi/costume/emihead.cpp
index 16eb8ebdba..4d12f225a2 100644
--- a/engines/grim/emi/costume/emihead.cpp
+++ b/engines/grim/emi/costume/emihead.cpp
@@ -101,7 +101,8 @@ void EMIHead::lookAt(bool entering, const Math::Vector3d &point, float rate, con
 
 	if (_headRot != lookAtQuat) {
 		Math::Quaternion diff = _headRot.inverse() * lookAtQuat;
-		float angle = 2 * acos(diff.w());
+		diff.normalize();
+		float angle = 2 * acos(fminf(fmaxf(diff.w(), -1.0f), 1.0f));
 		if (diff.w() < 0.0f) {
 			angle = 2 * (float)M_PI - angle;
 		}
diff --git a/engines/grim/emi/modelemi.cpp b/engines/grim/emi/modelemi.cpp
index 57d0161b91..57771cee84 100644
--- a/engines/grim/emi/modelemi.cpp
+++ b/engines/grim/emi/modelemi.cpp
@@ -369,7 +369,7 @@ void EMIModel::updateLighting(const Math::Matrix4 &modelToWorld) {
 					if (cosAngle < 0.0f)
 						continue;
 
-					float angle = acos(cosAngle);
+					float angle = acos(fminf(cosAngle, 1.0f));
 					if (angle > l->_penumbraangle)
 						continue;
 
diff --git a/engines/grim/emi/sound/track.cpp b/engines/grim/emi/sound/track.cpp
index 6e88e8b35c..1b798405e3 100644
--- a/engines/grim/emi/sound/track.cpp
+++ b/engines/grim/emi/sound/track.cpp
@@ -85,9 +85,10 @@ void SoundTrack::updatePosition() {
 	Math::Vector3d cameraPos = setup->_pos;
 	Math::Vector3d vector = _pos - cameraPos;
 	float distance = vector.getMagnitude();
-	_attenuation = MAX(0.0f, 1.0f - distance / (_volume * 100.0f / Audio::Mixer::kMaxChannelVolume));
-	if (!isfinite(_attenuation)) {
+	if (_volume == 0) {
 		_attenuation = 0.0f;
+	} else {
+		_attenuation = fmaxf(0.0f, 1.0f - distance / (_volume * 100.0f / Audio::Mixer::kMaxChannelVolume));
 	}
 
 	Math::Matrix4 worldRot = setup->_rot;




More information about the Scummvm-git-logs mailing list