Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ void ControlBar::populatePurchaseScience( Player* player )
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:ProgressBarExperience" ) );
if(win)
{
Int progress;
progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
const Int progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / (player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
GadgetProgressBarSetProgress(win, progress);
}

Expand Down Expand Up @@ -484,8 +483,7 @@ void ControlBar::updateContextPurchaseScience()
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:ProgressBarExperience" ) );
if(win)
{
Int progress;
progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
const Int progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / (player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
GadgetProgressBarSetProgress(win, progress);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,8 @@ void W3DCommandBarGenExpDraw( GameWindow *window, WinInstanceData *instData )
static const Image *endBar = TheMappedImageCollection->findImageByName("GenExpBarTop1");
static const Image *beginBar = TheMappedImageCollection->findImageByName("GenExpBarBottom1");
static const Image *centerBar = TheMappedImageCollection->findImageByName("GenExpBar1");
Int progress = 0;
Int skillPointsRequired = player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown();

// TheSuperHackers @bugfix Mauller 04/05/2025 Prevent possible division by zero
if ( skillPointsRequired > 0)
{
progress = ( ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / skillPointsRequired );
}
Int progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / (player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
Comment thread
Caball009 marked this conversation as resolved.

if(progress <= 0)
return;
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ class Player : public Snapshot
*/
Bool addScience(ScienceType science);

void setSafeLevels(Int levelUp, Int levelDown);

public:
Int getSkillPoints() const { return m_skillPoints; }
Int getSciencePurchasePoints() const { return m_sciencePurchasePoints; }
Expand Down
25 changes: 20 additions & 5 deletions GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,7 @@ void Player::resetRank()
m_rankLevel = 1;
m_skillPoints = 0;
const RankInfo* nextRank = TheRankInfoStore->getRankInfo(m_rankLevel+1);
m_levelUp = nextRank ? nextRank->m_skillPointsNeeded : INT_MAX;
m_levelDown = 0;
setSafeLevels(nextRank ? nextRank->m_skillPointsNeeded : INT_MAX, 0);
m_sciences.clear();
m_sciencePurchasePoints = getPlayerTemplate() ? getPlayerTemplate()->getIntrinsicSciencePurchasePoints() : 0;
const RankInfo* curRank = TheRankInfoStore->getRankInfo(m_rankLevel);
Expand Down Expand Up @@ -2762,7 +2761,8 @@ Bool Player::setRankLevel(Int newLevel)
}

const RankInfo* nextRank = TheRankInfoStore->getRankInfo(newLevel + 1);
m_levelUp = nextRank ? nextRank->m_skillPointsNeeded : INT_MAX;
setSafeLevels(nextRank ? nextRank->m_skillPointsNeeded : INT_MAX, m_levelDown);

m_rankLevel = newLevel;

DEBUG_ASSERTCRASH(m_skillPoints >= m_levelDown && m_skillPoints < m_levelUp, ("hmm, wrong"));
Expand All @@ -2788,6 +2788,22 @@ Bool Player::setRankLevel(Int newLevel)
return true;
}

//=============================================================================
void Player::setSafeLevels(Int levelUp, Int levelDown)
{
if (levelUp == levelDown)
{
// TheSuperHackers @bugfix Prevent possible division by zero in the control bar code.
m_levelUp = INT_MAX;
m_levelDown = 0;
}
Comment on lines +2794 to +2799

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Do not terminalize duplicates

Equal adjacent SkillPointsNeeded values are valid custom-rank input for the crash case this code handles. When a player reaches rank N and rank N+1 has the same threshold, this branch replaces the next threshold with INT_MAX; addSkillPoints() can then never advance the player to rank N+1 even though the threshold is already met. Handle a zero-width transition without converting it into the terminal-rank sentinel.

Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
Line: 2794-2799

Comment:
**Do not terminalize duplicates**

Equal adjacent `SkillPointsNeeded` values are valid custom-rank input for the crash case this code handles. When a player reaches rank N and rank N+1 has the same threshold, this branch replaces the next threshold with `INT_MAX`; `addSkillPoints()` can then never advance the player to rank N+1 even though the threshold is already met. Handle a zero-width transition without converting it into the terminal-rank sentinel.

How can I resolve this? If you propose a fix, please make it concise.

else
{
m_levelUp = levelUp;
m_levelDown = levelDown;
}
}

//=============================================================================
Bool Player::hasScience(ScienceType t) const
{
Expand Down Expand Up @@ -4588,6 +4604,5 @@ void Player::xfer( Xfer *xfer )
// ------------------------------------------------------------------------------------------------
void Player::loadPostProcess()
{

setSafeLevels(m_levelUp, m_levelDown);
}

Loading