Skip to content

Commit

Permalink
Fix division by zero in GuiScrollBar function (raysan5#396)
Browse files Browse the repository at this point in the history
When trying to use the floating window example, I got several times some crashes when expanding the window size. 
It's caused in the GuiScrollBar function, when the maxValue is equal to the minValue (I don't know if this case is intended in the first place).
Because valueRange variable is maxValue minus minValue, then it is equal to 0, and triggers a crash later, when we use it in division (division by 0).

I'm not sure if it's the best fix, maybe minValue == maxValue is not indentend in the first place and we should fix this problem earlier?
  • Loading branch information
Elkantor authored Apr 11, 2024
1 parent 85549da commit 34ef120
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/raygui.h
Original file line number Diff line number Diff line change
Expand Up @@ -5173,7 +5173,9 @@ static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
if (value > maxValue) value = maxValue;
if (value < minValue) value = minValue;

const int valueRange = maxValue - minValue;
int valueRange = maxValue - minValue;
if (valueRange <= 0) valueRange = 1;

int sliderSize = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE);
if (sliderSize < 1) sliderSize = 1; // TODO: Consider a minimum slider size

Expand Down

0 comments on commit 34ef120

Please sign in to comment.