From af343c36e1b6868725141e118ea06edae3a16db6 Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Wed, 11 Nov 2026 09:58:49 -0700 Subject: [PATCH 1/6] refactor: Replace _isnan and _finite with std::isnan and std::isfinite _isnan and _finite are MSVC CRT functions from . Use the standard functions instead. The new cmath_adapter.h gives VC6 std::isnan and std::isfinite built on _isnan and _finite, because neither VC6 nor STLport 4.5.3 has them. Co-Authored-By: Claude Opus 5.5 --- Core/GameEngine/Include/Precompiled/PreRTS.h | 1 + .../Source/Common/System/GameCommon.cpp | 4 +- .../Source/WWVegas/WW3D2/motchan.cpp | 2 +- .../Source/WWVegas/WW3D2/sortingrenderer.cpp | 4 +- .../Source/WWVegas/WW3D2/streakRender.cpp | 2 +- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 1 + Dependencies/Utility/CMakeLists.txt | 1 + Dependencies/Utility/Utility/cmath_adapter.h | 60 +++++++++++++++++++ .../GameEngine/Source/Common/Thing/Thing.cpp | 10 ++-- .../GameEngine/Source/GameClient/Drawable.cpp | 2 +- .../Source/GameLogic/Object/Object.cpp | 2 +- .../GameLogic/Object/Update/AIUpdate.cpp | 4 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 14 ++--- .../GameEngine/Source/Common/Thing/Thing.cpp | 10 ++-- .../GameEngine/Source/GameClient/Drawable.cpp | 2 +- .../Source/GameLogic/Object/Object.cpp | 2 +- .../GameLogic/Object/Update/AIUpdate.cpp | 4 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 14 ++--- 18 files changed, 101 insertions(+), 38 deletions(-) create mode 100644 Dependencies/Utility/Utility/cmath_adapter.h diff --git a/Core/GameEngine/Include/Precompiled/PreRTS.h b/Core/GameEngine/Include/Precompiled/PreRTS.h index 7653c34d972..1cfc2216192 100644 --- a/Core/GameEngine/Include/Precompiled/PreRTS.h +++ b/Core/GameEngine/Include/Precompiled/PreRTS.h @@ -48,6 +48,7 @@ class STLSpecialAlloc; #include #include +#include #include #include #include diff --git a/Core/GameEngine/Source/Common/System/GameCommon.cpp b/Core/GameEngine/Source/Common/System/GameCommon.cpp index 7f8b4ff4015..90688b63473 100644 --- a/Core/GameEngine/Source/Common/System/GameCommon.cpp +++ b/Core/GameEngine/Source/Common/System/GameCommon.cpp @@ -53,9 +53,9 @@ static_assert(ARRAY_SIZE(TheRelationshipNames) == RELATIONSHIP_COUNT + 1, "Incor // TheSuperHackers @todo DO NOT USE THIS FUNCTION! Use WWMath::Normalize_Angle instead. Delete this. Real normalizeAngle(Real angle) { - DEBUG_ASSERTCRASH(!_isnan(angle), ("Angle is NAN in normalizeAngle!")); + DEBUG_ASSERTCRASH(!std::isnan(angle), ("Angle is NAN in normalizeAngle!")); - if( _isnan(angle) ) + if( std::isnan(angle) ) return 0;// ARGH!!!! Don't assert and then not handle it! Error bad! Fix error! while (angle > PI) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 2485d251768..317d4c5d525 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -1264,7 +1264,7 @@ return; int i=0; for (;i100000.0f) value=0.0f; if (value<-100000.0f) value=0.0f; Data[i]=value; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp index 973aaf61c21..7608a2f3319 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp @@ -474,7 +474,7 @@ void SortingRendererClass::Flush_Sorting_Pool() tis_ptr->tri.k = idx3 + vertex_array_offset; tis_ptr->idx = node_id; tis_ptr->z = (v1->z + v2->z + v3->z)/3.0f; - DEBUG_ASSERTCRASH((! _isnan(tis_ptr->z) && _finite(tis_ptr->z)), ("Triangle has invalid center")); + DEBUG_ASSERTCRASH((! std::isnan(tis_ptr->z) && std::isfinite(tis_ptr->z)), ("Triangle has invalid center")); } } else { for (int i=0;ipolygon_count;++i) { @@ -497,7 +497,7 @@ void SortingRendererClass::Flush_Sorting_Pool() tis_ptr->z = (mtx[2][0]*(v1->x + v2->x + v3->x) + mtx[2][1]*(v1->y + v2->y + v3->y) + mtx[2][2]*(v1->z + v2->z + v3->z))/3.0f + mtx[2][3]; - DEBUG_ASSERTCRASH((! _isnan(tis_ptr->z) && _finite(tis_ptr->z)), ("Triangle has invalid center")); + DEBUG_ASSERTCRASH((! std::isnan(tis_ptr->z) && std::isfinite(tis_ptr->z)), ("Triangle has invalid center")); } } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp b/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp index 22b5e27b60a..06f423d608d 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp @@ -1334,7 +1334,7 @@ void StreakRendererClass::RenderStreak for (i=0; i +#include #include #include #include diff --git a/Dependencies/Utility/CMakeLists.txt b/Dependencies/Utility/CMakeLists.txt index b49fb225373..6b8d0e2dfd0 100644 --- a/Dependencies/Utility/CMakeLists.txt +++ b/Dependencies/Utility/CMakeLists.txt @@ -6,6 +6,7 @@ set(UTILITY_SRC Utility/atomic_adapter.h Utility/atomic_x86interlocked.inl Utility/bit_adapter.h + Utility/cmath_adapter.h Utility/compat.h Utility/comsupp_compat.h Utility/endian_compat.h diff --git a/Dependencies/Utility/Utility/cmath_adapter.h b/Dependencies/Utility/Utility/cmath_adapter.h new file mode 100644 index 00000000000..f79db9c3103 --- /dev/null +++ b/Dependencies/Utility/Utility/cmath_adapter.h @@ -0,0 +1,60 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +// This file provides std::isnan and std::isfinite. The of VC6 and STLport 4.5.3 has neither, and VC6 +// gets functions that call _isnan and _finite of . +// +// The VC6 functions differ from the standard functions in these points: +// - There are only float and double overloads. An integer or long double argument is ambiguous. +// - A float argument is converted to double before the check. NaN and infinity stay NaN and infinity in that +// conversion, so the result is the same. + +#pragma once + +#if defined(_MSC_VER) && _MSC_VER < 1300 + +#include + +namespace std +{ +inline bool isnan(float x) +{ + return _isnan(x) != 0; +} + +inline bool isnan(double x) +{ + return _isnan(x) != 0; +} + +inline bool isfinite(float x) +{ + return _finite(x) != 0; +} + +inline bool isfinite(double x) +{ + return _finite(x) != 0; +} +} + +#else + +#include + +#endif diff --git a/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp b/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp index 5a672cfb889..3d67d6ccf68 100644 --- a/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp +++ b/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp @@ -168,7 +168,7 @@ void Thing::setPositionZ( Real z ) TheTerrainLogic->alignOnTerrain(getOrientation(), pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -181,7 +181,7 @@ void Thing::setPosition( const Coord3D *pos ) Coord3D oldPos = m_cachedPos; Matrix3D oldMtx = m_transform; - //DEBUG_ASSERTCRASH(!(_isnan(pos->x) || _isnan(pos->y) || _isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + //DEBUG_ASSERTCRASH(!(std::isnan(pos->x) || std::isnan(pos->y) || std::isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); m_transform.Set_X_Translation( pos->x ); m_transform.Set_Y_Translation( pos->y ); m_transform.Set_Z_Translation( pos->z ); @@ -197,7 +197,7 @@ void Thing::setPosition( const Coord3D *pos ) TheTerrainLogic->alignOnTerrain(getOrientation(), *pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -247,7 +247,7 @@ void Thing::setOrientation( Real angle ) m_cacheFlags &= ~VALID_DIRVECTOR; // but don't clear the altitude flags. reactToTransformChange(&oldMtx, &oldPos, oldAngle); - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -268,7 +268,7 @@ void Thing::setTransformMatrix( const Matrix3D *mx ) m_cacheFlags = 0; reactToTransformChange(&oldMtx, &oldPos, oldAngle); - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp b/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp index 36b99f5c77c..33940636f4c 100644 --- a/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp @@ -2484,7 +2484,7 @@ const AudioEventRTS& Drawable::getAmbientSoundByDamage(BodyDamageType dt) void Drawable::validatePos() const { const Coord3D* ourPos = getPosition(); - if (_isnan(ourPos->x) || _isnan(ourPos->y) || _isnan(ourPos->z)) + if (std::isnan(ourPos->x) || std::isnan(ourPos->y) || std::isnan(ourPos->z)) { DEBUG_CRASH(("Drawable/Object position NAN! '%s'", getTemplate()->getName().str())); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index c1c6bfe91c3..dc413c15d94 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1698,7 +1698,7 @@ void Object::reactToTurretChange( WhichTurretType turret, Real oldRotation, Real void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle) { //USE_PERF_TIMER(Object_reactToTransformChange) - if(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)) { + if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) { DEBUG_CRASH(("Object pos is nan.")); TheGameLogic->destroyObject(this); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 1d0ef142264..1253d38460c 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2291,7 +2291,7 @@ void AIUpdateInterface::setLocomotorGoalPositionExplicit(const Coord3D& newPos) m_locomotorGoalType = POSITION_EXPLICIT; m_locomotorGoalData = newPos; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalPositionExplicit")); } @@ -2304,7 +2304,7 @@ void AIUpdateInterface::setLocomotorGoalOrientation(Real angle) m_locomotorGoalType = ANGLE; m_locomotorGoalData.x = angle; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalOrientation")); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 2a302af61f0..f15f6ea694d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -297,9 +297,9 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) { // TheSuperHackers @info helmutbuhler 06/05/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC - DEBUG_ASSERTCRASH(!(_isnan(force->x) || _isnan(force->y) || _isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); #endif - if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z)) { + if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) { return; } // F = ma --> a = F/m (divide force by mass) @@ -319,8 +319,8 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) m_accel.y += modForce.y * massInv; m_accel.z += modForce.z * massInv; - //DEBUG_ASSERTCRASH(!(_isnan(m_accel.x) || _isnan(m_accel.y) || _isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); - //DEBUG_ASSERTCRASH(!(_isnan(m_vel.x) || _isnan(m_vel.y) || _isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_accel.x) || std::isnan(m_accel.y) || std::isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_vel.x) || std::isnan(m_vel.y) || std::isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); //DEBUG_ASSERTCRASH(fabs(force->z) < 3, ("unlikely z-force")); #ifdef SLEEPY_PHYSICS if (getFlag(IS_IN_UPDATE)) @@ -593,8 +593,8 @@ UpdateSleepTime PhysicsBehavior::update() mtx.Adjust_Z_Translation(m_vel.z); } - if (_isnan(mtx.Get_X_Translation()) || _isnan(mtx.Get_Y_Translation()) || - _isnan(mtx.Get_Z_Translation())) { + if (std::isnan(mtx.Get_X_Translation()) || std::isnan(mtx.Get_Y_Translation()) || + std::isnan(mtx.Get_Z_Translation())) { DEBUG_CRASH(("Object position is NAN, deleting.")); TheGameLogic->destroyObject(obj); } @@ -1339,7 +1339,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 force.x = factor * delta.x / dist; force.y = factor * delta.y / dist; force.z = factor * delta.z / dist; // will be zero for 2d case. - DEBUG_ASSERTCRASH(!(_isnan(force.x) || _isnan(force.y) || _isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force.x) || std::isnan(force.y) || std::isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); applyForce( &force ); } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp index 26ae3a88793..89a5be83922 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp @@ -168,7 +168,7 @@ void Thing::setPositionZ( Real z ) TheTerrainLogic->alignOnTerrain(getOrientation(), pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -181,7 +181,7 @@ void Thing::setPosition( const Coord3D *pos ) Coord3D oldPos = m_cachedPos; Matrix3D oldMtx = m_transform; - //DEBUG_ASSERTCRASH(!(_isnan(pos->x) || _isnan(pos->y) || _isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + //DEBUG_ASSERTCRASH(!(std::isnan(pos->x) || std::isnan(pos->y) || std::isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); m_transform.Set_X_Translation( pos->x ); m_transform.Set_Y_Translation( pos->y ); m_transform.Set_Z_Translation( pos->z ); @@ -197,7 +197,7 @@ void Thing::setPosition( const Coord3D *pos ) TheTerrainLogic->alignOnTerrain(getOrientation(), *pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -247,7 +247,7 @@ void Thing::setOrientation( Real angle ) m_cacheFlags &= ~VALID_DIRVECTOR; // but don't clear the altitude flags. reactToTransformChange(&oldMtx, &oldPos, oldAngle); - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -268,7 +268,7 @@ void Thing::setTransformMatrix( const Matrix3D *mx ) m_cacheFlags = 0; reactToTransformChange(&oldMtx, &oldPos, oldAngle); - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp index 3136edbf55d..0fbf841b40e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp @@ -2486,7 +2486,7 @@ const AudioEventRTS& Drawable::getAmbientSoundByDamage(BodyDamageType dt) void Drawable::validatePos() const { const Coord3D* ourPos = getPosition(); - if (_isnan(ourPos->x) || _isnan(ourPos->y) || _isnan(ourPos->z)) + if (std::isnan(ourPos->x) || std::isnan(ourPos->y) || std::isnan(ourPos->z)) { DEBUG_CRASH(("Drawable/Object position NAN! '%s'", getTemplate()->getName().str())); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index 88028578414..47d4aa32986 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1858,7 +1858,7 @@ void Object::reactToTurretChange( WhichTurretType turret, Real oldRotation, Real void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle) { //USE_PERF_TIMER(Object_reactToTransformChange) - if(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)) { + if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) { DEBUG_CRASH(("Object pos is nan.")); TheGameLogic->destroyObject(this); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 926ca274b4f..b73027cbdf4 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2333,7 +2333,7 @@ void AIUpdateInterface::setLocomotorGoalPositionExplicit(const Coord3D& newPos) m_locomotorGoalType = POSITION_EXPLICIT; m_locomotorGoalData = newPos; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalPositionExplicit")); } @@ -2346,7 +2346,7 @@ void AIUpdateInterface::setLocomotorGoalOrientation(Real angle) m_locomotorGoalType = ANGLE; m_locomotorGoalData.x = angle; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalOrientation")); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index a073dc64649..dad9f715e22 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -315,9 +315,9 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) { // TheSuperHackers @info helmutbuhler 06/05/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC - DEBUG_ASSERTCRASH(!(_isnan(force->x) || _isnan(force->y) || _isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); #endif - if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z)) { + if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) { return; } // F = ma --> a = F/m (divide force by mass) @@ -337,8 +337,8 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) m_accel.y += modForce.y * massInv; m_accel.z += modForce.z * massInv; - //DEBUG_ASSERTCRASH(!(_isnan(m_accel.x) || _isnan(m_accel.y) || _isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); - //DEBUG_ASSERTCRASH(!(_isnan(m_vel.x) || _isnan(m_vel.y) || _isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_accel.x) || std::isnan(m_accel.y) || std::isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_vel.x) || std::isnan(m_vel.y) || std::isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); //DEBUG_ASSERTCRASH(fabs(force->z) < 3, ("unlikely z-force")); #ifdef SLEEPY_PHYSICS if (getFlag(IS_IN_UPDATE)) @@ -677,8 +677,8 @@ UpdateSleepTime PhysicsBehavior::update() mtx.Adjust_Z_Translation(m_vel.z); } - if (_isnan(mtx.Get_X_Translation()) || _isnan(mtx.Get_Y_Translation()) || - _isnan(mtx.Get_Z_Translation())) { + if (std::isnan(mtx.Get_X_Translation()) || std::isnan(mtx.Get_Y_Translation()) || + std::isnan(mtx.Get_Z_Translation())) { DEBUG_CRASH(("Object position is NAN, deleting.")); TheGameLogic->destroyObject(obj); } @@ -1463,7 +1463,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 force.x = factor * delta.x / dist; force.y = factor * delta.y / dist; force.z = factor * delta.z / dist; // will be zero for 2d case. - DEBUG_ASSERTCRASH(!(_isnan(force.x) || _isnan(force.y) || _isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force.x) || std::isnan(force.y) || std::isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); applyForce( &force ); } From 910c36524dae4cf50513e7cce896e7ef9371b9fe Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Mon, 16 Nov 2026 19:32:35 -0700 Subject: [PATCH 2/6] style(motchan): Move if body to its own line Co-Authored-By: Claude Opus 5.5 --- Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 317d4c5d525..3aceeeb6dca 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -1264,7 +1264,8 @@ return; int i=0; for (;i100000.0f) value=0.0f; if (value<-100000.0f) value=0.0f; Data[i]=value; From b01607b89fcd1defe588610433fb714c0badffd8 Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Tue, 17 Nov 2026 01:11:33 -0700 Subject: [PATCH 3/6] style: Put opening braces of the changed NaN checks on their own lines Co-Authored-By: Claude Opus 5.5 --- Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp | 3 ++- .../Source/GameLogic/Object/Update/PhysicsUpdate.cpp | 6 ++++-- .../Code/GameEngine/Source/GameLogic/Object/Object.cpp | 3 ++- .../Source/GameLogic/Object/Update/PhysicsUpdate.cpp | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index dc413c15d94..67b3228fab7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1698,7 +1698,8 @@ void Object::reactToTurretChange( WhichTurretType turret, Real oldRotation, Real void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle) { //USE_PERF_TIMER(Object_reactToTransformChange) - if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) { + if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) + { DEBUG_CRASH(("Object pos is nan.")); TheGameLogic->destroyObject(this); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index f15f6ea694d..21fa0e70fd1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -299,7 +299,8 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC DEBUG_ASSERTCRASH(!(std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); #endif - if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) { + if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) + { return; } // F = ma --> a = F/m (divide force by mass) @@ -594,7 +595,8 @@ UpdateSleepTime PhysicsBehavior::update() } if (std::isnan(mtx.Get_X_Translation()) || std::isnan(mtx.Get_Y_Translation()) || - std::isnan(mtx.Get_Z_Translation())) { + std::isnan(mtx.Get_Z_Translation())) + { DEBUG_CRASH(("Object position is NAN, deleting.")); TheGameLogic->destroyObject(obj); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index 47d4aa32986..ab1bf045988 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1858,7 +1858,8 @@ void Object::reactToTurretChange( WhichTurretType turret, Real oldRotation, Real void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle) { //USE_PERF_TIMER(Object_reactToTransformChange) - if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) { + if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) + { DEBUG_CRASH(("Object pos is nan.")); TheGameLogic->destroyObject(this); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index dad9f715e22..ace374c97d8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -317,7 +317,8 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC DEBUG_ASSERTCRASH(!(std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); #endif - if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) { + if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) + { return; } // F = ma --> a = F/m (divide force by mass) @@ -678,7 +679,8 @@ UpdateSleepTime PhysicsBehavior::update() } if (std::isnan(mtx.Get_X_Translation()) || std::isnan(mtx.Get_Y_Translation()) || - std::isnan(mtx.Get_Z_Translation())) { + std::isnan(mtx.Get_Z_Translation())) + { DEBUG_CRASH(("Object position is NAN, deleting.")); TheGameLogic->destroyObject(obj); } From e6daacd10caf05974dafa3e36c98ce55c01b5ce3 Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Tue, 17 Nov 2026 01:11:56 -0700 Subject: [PATCH 4/6] refactor(ww3d2): Include cmath_adapter.h in the files that call std::isnan wwmath.h does not call std::isnan or std::isfinite, so it should not include the adapter. The three WW3D2 files that do now include it themselves, as they do for bit_adapter.h. Co-Authored-By: Claude Opus 5.5 --- Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 1 + Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp | 1 + Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp | 1 + Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 1 - 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 3aceeeb6dca..b6ddc8dfa41 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -51,6 +51,7 @@ #include "WWMath/wwmath.h" #include "WWMath/quat.h" #include +#include //#include // Static Table, for Adaptive Delta Decompressor #define FILTER_TABLE_SIZE (256) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp index 7608a2f3319..7ebf54f88ea 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp @@ -48,6 +48,7 @@ #include "d3d8.h" #include "statistics.h" #include +#include #include #include diff --git a/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp b/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp index 06f423d608d..10e14ebc2d2 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp @@ -35,6 +35,7 @@ #include "WWMath/Vector3i.h" #include "WWLib/RANDOM.h" #include "WWMath/v3_rnd.h" +#include /* We have chunking logic which handles N segments at a time. To simplify the subdivision logic, diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 7f059ec7417..d27e4525315 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -38,7 +38,6 @@ #include "WWLib/always.h" #include -#include #include #include #include From d9851f196a30d0b3fde5c8c146fb15fec10f3dbd Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Tue, 17 Nov 2026 01:11:56 -0700 Subject: [PATCH 5/6] style(motchan): Add a blank line after the NaN check Co-Authored-By: Claude Opus 5.5 --- Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp index b6ddc8dfa41..78b081e13f1 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -1267,6 +1267,7 @@ return; float value=Data[i]; if (std::isnan(value)) value=0.0f; + if (value>100000.0f) value=0.0f; if (value<-100000.0f) value=0.0f; Data[i]=value; From e6d35c1b7d2ea34da137e5ec55a92033f117416e Mon Sep 17 00:00:00 2001 From: Jacob Ledbetter Date: Wed, 18 Nov 2026 17:52:28 -0700 Subject: [PATCH 6/6] refactor(wwmath): Read the float bits with std::bit_cast in Is_Valid_Float and Is_Valid_Double Both functions read the value through an unsigned long pointer, which breaks the strict aliasing rule. std::bit_cast copies the bits instead. std::isfinite would also do, but it needs in wwmath.h, and MSVC's adds float overloads of sin and fabs that change the math of WW3D2 files that do not include it today. Co-Authored-By: Claude Opus 5.5 --- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index d27e4525315..8bd70df01aa 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -967,8 +967,7 @@ WWINLINE double WWMath::Inverse_Lerp(double a, double b, float v) WWINLINE bool WWMath::Is_Valid_Float(float x) { - unsigned long * plong = (unsigned long *)(&x); - unsigned long exponent = ((*plong) & 0x7F800000) >> (32-9); + unsigned int exponent = (std::bit_cast(x) & 0x7F800000) >> (32-9); // if exponent is 0xFF, this is a NAN if (exponent == 0xFF) { @@ -979,8 +978,8 @@ WWINLINE bool WWMath::Is_Valid_Float(float x) WWINLINE bool WWMath::Is_Valid_Double(double x) { - unsigned long * plong = (unsigned long *)(&x) + 1; - unsigned long exponent = ((*plong) & 0x7FF00000) >> (32-12); + unsigned int high = (unsigned int)(std::bit_cast(x) >> 32); + unsigned int exponent = (high & 0x7FF00000) >> (32-12); // if exponent is 0x7FF, this is a NAN if (exponent == 0x7FF) {