Skip to content

Commit afd9c30

Browse files
authored
[GEN][ZH] Fix possible division by zero in W3DCommandBarGenExpDraw() (#810)
1 parent 916ee74 commit afd9c30

File tree

2 files changed

+16
-4
lines changed
  • Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks
  • GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks

2 files changed

+16
-4
lines changed

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,14 @@ void W3DCommandBarGenExpDraw( GameWindow *window, WinInstanceData *instData )
497497
static const Image *endBar = TheMappedImageCollection->findImageByName("GenExpBarTop1");
498498
static const Image *beginBar = TheMappedImageCollection->findImageByName("GenExpBarBottom1");
499499
static const Image *centerBar = TheMappedImageCollection->findImageByName("GenExpBar1");
500-
Int progress;
501-
progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
500+
Int progress = 0;
501+
Int skillPointsRequired = player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown();
502+
503+
// TheSuperHackers @bugfix Mauller 04/05/2025 Prevent possible division by zero
504+
if ( skillPointsRequired > 0)
505+
{
506+
progress = ( ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / skillPointsRequired );
507+
}
502508

503509
if(progress <= 0)
504510
return;

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,14 @@ void W3DCommandBarGenExpDraw( GameWindow *window, WinInstanceData *instData )
497497
static const Image *endBar = TheMappedImageCollection->findImageByName("GenExpBarTop1");
498498
static const Image *beginBar = TheMappedImageCollection->findImageByName("GenExpBarBottom1");
499499
static const Image *centerBar = TheMappedImageCollection->findImageByName("GenExpBar1");
500-
Int progress;
501-
progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
500+
Int progress = 0;
501+
Int skillPointsRequired = player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown();
502+
503+
// TheSuperHackers @bugfix Mauller 04/05/2025 Prevent possible division by zero
504+
if ( skillPointsRequired > 0)
505+
{
506+
progress = ( ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / skillPointsRequired );
507+
}
502508

503509
if(progress <= 0)
504510
return;

0 commit comments

Comments
 (0)