Skip to content

Commit b643498

Browse files
committed
[GEN][ZH] Fix possible division by zero in W3DCommandBarGenExpDraw()
1 parent 47e08d0 commit b643498

File tree

2 files changed

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

2 files changed

+14
-4
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,13 @@ 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 skillPointsChange = player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown();
502+
503+
// TheSuperHackers @bugfix Mauller 04/05/2025 Prevent possible division by zero
504+
if ( skillPointsChange > 0) {
505+
progress = (((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / skillPointsChange );
506+
}
502507

503508
if(progress <= 0)
504509
return;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,13 @@ 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 skillPointsChange = player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown();
502+
503+
// TheSuperHackers @bugfix Mauller 04/05/2025 Prevent possible division by zero
504+
if ( skillPointsChange > 0) {
505+
progress = (((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) / skillPointsChange );
506+
}
502507

503508
if(progress <= 0)
504509
return;

0 commit comments

Comments
 (0)