From e4241b4d9372d7a1104af4d570de7fc8a7aa80c6 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Sat, 3 Jan 2026 20:25:46 +0000 Subject: [PATCH] Fix division by zero in power bar GUI updates --- .../GameClient/GUI/GUICallbacks/W3DControlBar.cpp | 15 +++++++++++++++ .../GameClient/GUI/GUICallbacks/W3DControlBar.cpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp index a69e81a3a90..d8fb8c38047 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp @@ -171,6 +171,10 @@ void W3DPowerDraw( GameWindow *window, WinInstanceData *instData ) if( !slider || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageWidth() <= 0 ) + return; + Int range; range = logN(production, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals); if(range >= size.x) @@ -338,6 +342,10 @@ void W3DPowerDrawA( GameWindow *window, WinInstanceData *instData ) if( !slider || !endBar || !beginBar || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageWidth() <= 0 ) + return; + Int range; range = logN(production, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals); if(range >= size.x) @@ -516,6 +524,10 @@ void W3DCommandBarGenExpDraw( GameWindow *window, WinInstanceData *instData ) if( !endBar || !beginBar || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageHeight() <= 0 ) + return; + Int range; range = size.y * progress / 100; @@ -928,6 +940,9 @@ void W3DCommandBarHelpPopupDraw( GameWindow *window, WinInstanceData *instData ) if( !endBar || !beginBar || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageHeight() <= 0 ) + return; // Int range; // range = size.y; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp index eb8785fb7f6..c1f7ebf9149 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp @@ -171,6 +171,10 @@ void W3DPowerDraw( GameWindow *window, WinInstanceData *instData ) if( !slider || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageWidth() <= 0 ) + return; + Int range; range = logN(production, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals); if(range >= size.x) @@ -338,6 +342,10 @@ void W3DPowerDrawA( GameWindow *window, WinInstanceData *instData ) if( !slider || !endBar || !beginBar || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageWidth() <= 0 ) + return; + Int range; range = logN(production, TheGlobalData->m_powerBarBase) * (size.x / TheGlobalData->m_powerBarIntervals); if(range >= size.x) @@ -516,6 +524,10 @@ void W3DCommandBarGenExpDraw( GameWindow *window, WinInstanceData *instData ) if( !endBar || !beginBar || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageHeight() <= 0 ) + return; + Int range; range = size.y * progress / 100; @@ -928,6 +940,9 @@ void W3DCommandBarHelpPopupDraw( GameWindow *window, WinInstanceData *instData ) if( !endBar || !beginBar || !centerBar) return; + // Validate image dimensions to prevent division by zero + if( centerBar->getImageHeight() <= 0 ) + return; // Int range; // range = size.y;