[cpp] Fix float exception, closes #2583

This commit is contained in:
Mario Zechner 2024-07-24 13:49:42 +02:00
parent cd8dadc02a
commit aca86fa588
3 changed files with 8 additions and 7 deletions

View File

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

View File

@ -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();

View File

@ -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() {