Skip to content

[GEN][ZH] Fix Mismatch in Release Build when Logging is enabled #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Generals/Code/GameEngine/Source/Common/StateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,16 @@ State *StateMachine::internalGetState( StateID id )

if (i == m_stateMap.end())
{
DEBUG_CRASH(( "StateMachine::internalGetState(): Invalid state" ));
throw ERROR_BAD_ARG;
DEBUG_CRASH( ("StateMachine::internalGetState(): Invalid state for object %s using state %d", m_owner->getTemplate()->getName().str(), id) );
DEBUG_LOG(("Transitioning to state %d\n", (Int)id));
DEBUG_LOG(("Attempting to recover - locating default state...\n"));
i = m_stateMap.find(m_defaultStateID);
if (i == m_stateMap.end()) {
DEBUG_LOG(("Failed to located default state. Aborting...\n"));
throw ERROR_BAD_ARG;
} else {
DEBUG_LOG(("Located default state to recover.\n"));
}
}

return (*i).second;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,16 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName,
Real s = sin(angle);
Real c = cos(angle);

DEBUG_LOG(("Angle is %f sin %f, cos %f \n", 180*angle/PI, s, c));
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
// TheSuperHackers @info helmutbuhler 21/04/2025
// This log causes mismatch on Release when logging is enabled.
DEBUG_LOG(("Angle is %f sin %f, cos %f \n", 180*angle/PI, s, c));
DEBUG_LOG(("Offset is %f %f, new is %f, %f \n",
offset.x, offset.y,
offset.x*c - offset.y*s,
offset.y*c + offset.x*s
));
));
#endif
Coord3D buildPos = m_baseCenter;
buildPos.x += offset.x*c - offset.y*s;
buildPos.y += offset.y*c + offset.x*s;
Expand Down
6 changes: 6 additions & 0 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4028,8 +4028,11 @@ StateReturnType AIFollowWaypointPathState::update()
if (getAdjustsDestination() && ai->isDoingGroundMovement()) {
if (!TheAI->pathfinder()->adjustDestination(obj, ai->getLocomotorSet(), &m_goalPosition)) {
if (m_currentWaypoint) {
// This log causes mismatch on Release (TheSuperHackers @info helmutbuhler 05/05/2025)
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
DEBUG_LOG(("Breaking out of follow waypoint path %s of %s\n",
m_currentWaypoint->getName().str(), m_currentWaypoint->getPathLabel1().str()));
#endif
}
return STATE_FAILURE;
}
Expand Down Expand Up @@ -4098,8 +4101,11 @@ StateReturnType AIFollowWaypointPathState::update()
if (getAdjustsDestination() && ai->isDoingGroundMovement()) {
if (!TheAI->pathfinder()->adjustDestination(obj, ai->getLocomotorSet(), &m_goalPosition)) {
if (m_currentWaypoint) {
// This log causes mismatch on Release (TheSuperHackers @info helmutbuhler 05/05/2025)
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
DEBUG_LOG(("Breaking out of follow waypoint path %s of %s\n",
m_currentWaypoint->getName().str(), m_currentWaypoint->getPathLabel1().str()));
#endif
}
return STATE_FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ inline Real calcDistSqr(const Coord3D& a, const Coord3D& b)
Int GarrisonContain::findClosestFreeGarrisonPointIndex( Int conditionIndex,
const Coord3D *targetPos )
{
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
// TheSuperHackers @info helmutbuhler 05/05/2025
// This assert causes a mismatch on Release when DEBUG_CRASHING is enabled.
DEBUG_ASSERTCRASH(m_garrisonPointsInitialized, ("garrisonPoints are not inited"));
#endif

// sanity
if( targetPos == NULL || m_garrisonPointsInUse == MAX_GARRISON_POINTS )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ Real PhysicsBehavior::getZFriction() const
*/
void PhysicsBehavior::applyForce( const Coord3D *force )
{
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
// TheSuperHackers @info helmutbuhler 06/05/2025
// This assert causes a mismatch on Release when DEBUG_CRASHING is enabled.
DEBUG_ASSERTCRASH(!(_isnan(force->x) || _isnan(force->y) || _isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!\n"));
#endif
if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ State *StateMachine::internalGetState( StateID id )
if (i == m_stateMap.end())
{
DEBUG_CRASH( ("StateMachine::internalGetState(): Invalid state for object %s using state %d", m_owner->getTemplate()->getName().str(), id) );
DEBUG_LOG(("Transisioning to state #d\n", (Int)id));
DEBUG_LOG(("Transitioning to state %d\n", (Int)id));
DEBUG_LOG(("Attempting to recover - locating default state...\n"));
i = m_stateMap.find(m_defaultStateID);
if (i == m_stateMap.end()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,16 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName,
Real s = sin(angle);
Real c = cos(angle);

DEBUG_LOG(("buildAIBaseDefenseStructure -- Angle is %f sin %f, cos %f \n", 180*angle/PI, s, c));
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
// TheSuperHackers @info helmutbuhler 21/04/2025
// This log causes mismatch on Release when logging is enabled.
DEBUG_LOG(("buildAIBaseDefenseStructure -- Angle is %f sin %f, cos %f \n", 180*angle/PI, s, c));
DEBUG_LOG(("buildAIBaseDefenseStructure -- Offset is %f %f, Final Position is %f, %f \n",
offset.x, offset.y,
offset.x*c - offset.y*s,
offset.y*c + offset.x*s
));
));
#endif
Coord3D buildPos = m_baseCenter;
buildPos.x += offset.x*c - offset.y*s;
buildPos.y += offset.y*c + offset.x*s;
Expand Down
6 changes: 6 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4149,8 +4149,11 @@ StateReturnType AIFollowWaypointPathState::update()
if (getAdjustsDestination() && ai->isDoingGroundMovement()) {
if (!TheAI->pathfinder()->adjustDestination(obj, ai->getLocomotorSet(), &m_goalPosition)) {
if (m_currentWaypoint) {
// This log causes mismatch on Release (TheSuperHackers @info helmutbuhler 05/05/2025)
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
DEBUG_LOG(("Breaking out of follow waypoint path %s of %s\n",
m_currentWaypoint->getName().str(), m_currentWaypoint->getPathLabel1().str()));
#endif
}
return STATE_FAILURE;
}
Expand Down Expand Up @@ -4219,8 +4222,11 @@ StateReturnType AIFollowWaypointPathState::update()
if (getAdjustsDestination() && ai->isDoingGroundMovement()) {
if (!TheAI->pathfinder()->adjustDestination(obj, ai->getLocomotorSet(), &m_goalPosition)) {
if (m_currentWaypoint) {
// This log causes mismatch on Release (TheSuperHackers @info helmutbuhler 05/05/2025)
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
DEBUG_LOG(("Breaking out of follow waypoint path %s of %s\n",
m_currentWaypoint->getName().str(), m_currentWaypoint->getPathLabel1().str()));
#endif
}
return STATE_FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ inline Real calcDistSqr(const Coord3D& a, const Coord3D& b)
Int GarrisonContain::findClosestFreeGarrisonPointIndex( Int conditionIndex,
const Coord3D *targetPos )
{
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
// TheSuperHackers @info helmutbuhler 05/05/2025
// This assert causes a mismatch on Release when DEBUG_CRASHING is enabled.
DEBUG_ASSERTCRASH(m_garrisonPointsInitialized, ("garrisonPoints are not inited"));
#endif

// sanity
if( targetPos == NULL || m_garrisonPointsInUse == MAX_GARRISON_POINTS )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ Real PhysicsBehavior::getZFriction() const
*/
void PhysicsBehavior::applyForce( const Coord3D *force )
{
#if defined(RTS_DEBUG) || defined(RTS_INTERNAL)
// TheSuperHackers @info helmutbuhler 06/05/2025
// This assert causes a mismatch on Release when DEBUG_CRASHING is enabled.
DEBUG_ASSERTCRASH(!(_isnan(force->x) || _isnan(force->y) || _isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!\n"));
#endif
if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z)) {
return;
}
Expand Down
Loading