bugfix(controlbar): Fix possible divisions by zero in Control Bar code#2867
bugfix(controlbar): Fix possible divisions by zero in Control Bar code#2867Caball009 wants to merge 3 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp | Keeps both purchase-science progress calculations aligned with the player rank bounds. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp | Updates general-experience progress rendering to use the player rank interval directly. |
| GeneralsMD/Code/GameEngine/Include/Common/Player.h | Declares the private helper for normalizing rank bounds. |
| GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp | Uses the new helper during rank reset, rank changes, and post-load processing. |
Reviews (11): Last reviewed commit: "Avoided possible divisions by zero in Co..." | Re-trigger Greptile
47b4cdc to
2ac70a7
Compare
|
If skillPointsRequired is 0, than this implies that a rank up didn't go through - after all the player has enough points to rank up to the next level. So I wonder if the fix is at the wrong place |
| // TheSuperHackers @bugfix Caball009 12/07/2026 Prevent possible division by zero. | ||
| if (skillPointsRequired > 0) | ||
| { | ||
| progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / skillPointsRequired; |
There was a problem hiding this comment.
This code now exists at 3 locations. Maybe consolidate it to one?
2ac70a7 to
ed174e2
Compare
ed174e2 to
ede4635
Compare
ede4635 to
480a9a7
Compare
|
@greptileai re-review this pull request. |
| const RankInfo* nextRank = TheRankInfoStore->getRankInfo(m_rankLevel+1); | ||
| m_levelUp = nextRank ? nextRank->m_skillPointsNeeded : INT_MAX; | ||
|
|
||
| // TheSuperHackers @bugfix Prevent possible division by zero in the control bar code. |
There was a problem hiding this comment.
How about we introduce a hasNextRank function? Then it can be explicitly tested whether it has a next rank.
Reason: The current interface sort of implies that it can reach this INT_MAX points level to reach the next rank, but it is not possible.
There was a problem hiding this comment.
I'm not sure I understand. Is this relevant to the division by zero?
There was a problem hiding this comment.
Yes. Right now the code relies on MAX_INT to work, but its shady.
There was a problem hiding this comment.
Perhaps you can post some code for what you have in mind.
c8c0c76 to
2f4d086
Compare
fadf08f to
4444518
Compare
| if (levelUp == levelDown) | ||
| { | ||
| // TheSuperHackers @bugfix Prevent possible division by zero in the control bar code. | ||
| m_levelUp = INT_MAX; | ||
| m_levelDown = 0; | ||
| } |
There was a problem hiding this comment.
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.4444518 to
c4b084e
Compare
Using the modified rank file in #797, there are two more places the game would crash because of a division by zero; in
ControlBar::populatePurchaseScienceandControlBar::updateContextPurchaseScience.Issue reproduction steps:
Callstacks:
TODO: