Эх сурвалжийг харах

[cpp] Fix float exception, closes #2583

Mario Zechner 1 жил өмнө
parent
commit
aca86fa588

+ 2 - 0
spine-cpp/spine-cpp/include/spine/MathUtil.h

@@ -88,6 +88,8 @@ namespace spine {
 
 		static bool isNan(float v);
 
+        static float quietNan();
+
 		static float random();
 
 		static float randomTriangular(float min, float max);

+ 1 - 1
spine-cpp/spine-cpp/src/spine/AnimationState.cpp

@@ -921,7 +921,7 @@ void AnimationState::setAttachment(Skeleton &skeleton, Slot &slot, const String
 void AnimationState::queueEvents(TrackEntry *entry, float animationTime) {
 	float animationStart = entry->_animationStart, animationEnd = entry->_animationEnd;
 	float duration = animationEnd - animationStart;
-	float trackLastWrapped = MathUtil::fmod(entry->_trackLast, duration);
+	float trackLastWrapped = duration != 0 ? MathUtil::fmod(entry->_trackLast, duration) : MathUtil::quietNan();
 
 	// Queue events before complete.
 	size_t i = 0, n = _events.size();

+ 5 - 6
spine-cpp/spine-cpp/src/spine/MathUtil.cpp

@@ -30,6 +30,7 @@
 #include <spine/MathUtil.h>
 #include <math.h>
 #include <stdlib.h>
+#include <cmath>
 
 // Required for division by 0 in _isNaN on MSVC
 #ifdef _MSC_VER
@@ -99,14 +100,12 @@ float MathUtil::cosDeg(float degrees) {
 	return (float) ::cos(degrees * MathUtil::Deg_Rad);
 }
 
-/* Need to pass 0 as an argument, so VC++ doesn't error with C2124 */
-static bool _isNan(float value, float zero) {
-	float _nan = (float) 0.0 / zero;
-	return 0 == memcmp((void *) &value, (void *) &_nan, sizeof(value));
+bool MathUtil::isNan(float v) {
+	return std::isnan(v);
 }
 
-bool MathUtil::isNan(float v) {
-	return _isNan(v, 0);
+float MathUtil::quietNan() {
+    return std::nan("");
 }
 
 float MathUtil::random() {