mirror of
https://github.com/raysan5/raygui.git
synced 2026-02-03 04:39:18 -05:00
Avoid control crash on NULL pointers
This commit is contained in:
24
src/raygui.h
24
src/raygui.h
@ -1667,6 +1667,9 @@ int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
|
|
||||||
|
Rectangle temp = { 0 };
|
||||||
|
if (view == NULL) view = &temp;
|
||||||
|
|
||||||
Vector2 scrollPos = { 0.0f, 0.0f };
|
Vector2 scrollPos = { 0.0f, 0.0f };
|
||||||
if (scroll != NULL) scrollPos = *scroll;
|
if (scroll != NULL) scrollPos = *scroll;
|
||||||
|
|
||||||
@ -1887,6 +1890,9 @@ int GuiToggle(Rectangle bounds, const char *text, bool *active)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
|
|
||||||
|
bool temp = false;
|
||||||
|
if (active == NULL) active = &temp;
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
|
if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
|
||||||
@ -1936,6 +1942,9 @@ int GuiToggleGroup(Rectangle bounds, const char *text, int *active)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
float initBoundsX = bounds.x;
|
float initBoundsX = bounds.x;
|
||||||
|
|
||||||
|
bool temp = false;
|
||||||
|
if (active == NULL) active = &temp;
|
||||||
|
|
||||||
bool toggle = false; // Required for individual toggles
|
bool toggle = false; // Required for individual toggles
|
||||||
|
|
||||||
// Get substrings items from text (items pointers)
|
// Get substrings items from text (items pointers)
|
||||||
@ -1978,6 +1987,9 @@ int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
|
|
||||||
|
bool temp = false;
|
||||||
|
if (checked == NULL) checked = &temp;
|
||||||
|
|
||||||
Rectangle textBounds = { 0 };
|
Rectangle textBounds = { 0 };
|
||||||
|
|
||||||
if (text != NULL)
|
if (text != NULL)
|
||||||
@ -2038,6 +2050,9 @@ int GuiComboBox(Rectangle bounds, const char *text, int *active)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
|
|
||||||
|
int temp = 0;
|
||||||
|
if (active == NULL) active = &temp;
|
||||||
|
|
||||||
bounds.width -= (GuiGetStyle(COMBOBOX, COMBO_BUTTON_WIDTH) + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING));
|
bounds.width -= (GuiGetStyle(COMBOBOX, COMBO_BUTTON_WIDTH) + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING));
|
||||||
|
|
||||||
Rectangle selector = { (float)bounds.x + bounds.width + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING),
|
Rectangle selector = { (float)bounds.x + bounds.width + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING),
|
||||||
@ -2673,6 +2688,9 @@ int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight,
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
|
|
||||||
|
float temp = (maxValue - minValue)/2.0f;
|
||||||
|
if (value == NULL) value = &temp;
|
||||||
|
|
||||||
int sliderValue = (int)(((*value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
|
int sliderValue = (int)(((*value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
|
||||||
|
|
||||||
Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, SLIDER_PADDING),
|
Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, SLIDER_PADDING),
|
||||||
@ -2797,6 +2815,9 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
GuiState state = guiState;
|
GuiState state = guiState;
|
||||||
|
|
||||||
|
float temp = (maxValue - minValue)/2.0f;
|
||||||
|
if (value == NULL) value = &temp;
|
||||||
|
|
||||||
Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH),
|
Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH),
|
||||||
bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING), 0,
|
bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING), 0,
|
||||||
bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING) };
|
bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING) };
|
||||||
@ -3311,6 +3332,9 @@ int GuiColorPicker(Rectangle bounds, const char *text, Color *color)
|
|||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
Color temp = { 200, 0, 0, 255 };
|
||||||
|
if (color == NULL) color = &temp;
|
||||||
|
|
||||||
GuiColorPanel(bounds, NULL, color);
|
GuiColorPanel(bounds, NULL, color);
|
||||||
|
|
||||||
Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
|
Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
|
||||||
|
|||||||
Reference in New Issue
Block a user