From 90ff11fe98e8ed81c8fb1045a8dbc78e48c81609 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 20 Apr 2021 07:36:17 +1000 Subject: [PATCH] Fix crash if you type text into search filter input widget in servers list menu, press left (to move caret inside the text), then go back to main menu, and then sign in again (Thanks GuzzDoritos) --- src/Gui.c | 11 ----------- src/Gui.h | 2 -- src/LScreens.c | 3 ++- src/LWidgets.c | 11 ++++++----- src/LWidgets.h | 1 + 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Gui.c b/src/Gui.c index cb03a08f0..ebfe6caa4 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -385,17 +385,6 @@ int Widget_Contains(void* widget, int x, int y) { /*########################################################################################################################* *-------------------------------------------------------Screen base-------------------------------------------------------* *#########################################################################################################################*/ -void Screen_RenderWidgets(void* screen, double delta) { - struct Screen* s = (struct Screen*)screen; - struct Widget** widgets = s->widgets; - int i; - - for (i = 0; i < s->numWidgets; i++) { - if (!widgets[i]) continue; - Elem_Render(widgets[i], delta); - } -} - void Screen_Render2Widgets(void* screen, double delta) { struct Screen* s = (struct Screen*)screen; struct Widget** widgets = s->widgets; diff --git a/src/Gui.h b/src/Gui.h index 23c7ffa61..39db003c2 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -102,8 +102,6 @@ struct ScreenVTABLE { /* Represents a container of widgets and other 2D elements. May cover entire window. */ struct Screen { Screen_Body }; -/* Calls Elem_Render on each widget in the screen. */ -void Screen_RenderWidgets(void* screen, double delta); /* Calls Widget_Render2 on each widget in the screen. */ void Screen_Render2Widgets(void* screen, double delta); void Screen_UpdateVb(void* screen); diff --git a/src/LScreens.c b/src/LScreens.c index 04a3bf325..e9c014128 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1298,8 +1298,9 @@ static void ServersScreen_Show(struct LScreen* s_) { Drawer2D_MakeFont(&s->rowFont, 11, FONT_FLAGS_NONE); s->table.rowFont = &s->rowFont; - /* also resets hash and filter */ LTable_Reset(&s->table); + LInput_ClearText(&s->iptHash); + LInput_ClearText(&s->iptSearch); ServersScreen_ReloadServers(s); /* This is so typing on keyboard by default searchs server list */ diff --git a/src/LWidgets.c b/src/LWidgets.c index c916fb621..99a997f9e 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -529,6 +529,11 @@ void LInput_SetText(struct LInput* w, const cc_string* text_) { LInput_ClampCaret(w); } +void LInput_ClearText(struct LInput* w) { + w->text.length = 0; + w->caretPos = -1; +} + static CC_NOINLINE cc_bool LInput_AppendRaw(struct LInput* w, char c) { if (w->TextFilter(c) && w->text.length < w->text.capacity) { if (w->caretPos == -1) { @@ -587,10 +592,9 @@ void LInput_Delete(struct LInput* w) { void LInput_Clear(struct LInput* w) { if (!w->text.length) return; - w->text.length = 0; + LInput_ClearText(w); if (w->TextChanged) w->TextChanged(w); - w->caretPos = -1; LWidget_Redraw(w); } @@ -1172,9 +1176,6 @@ void LTable_Reset(struct LTable* w) { w->rowsCount = 0; sortingCol = -1; w->_wheelAcc = 0.0f; - - w->selectedHash->length = 0; - w->filter->length = 0; } void LTable_ApplyFilter(struct LTable* w) { diff --git a/src/LWidgets.h b/src/LWidgets.h index e87c364ed..89b018d28 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -85,6 +85,7 @@ struct LInput { }; CC_NOINLINE void LInput_Init(struct LScreen* s, struct LInput* w, int width, const char* hintText); CC_NOINLINE void LInput_SetText(struct LInput* w, const cc_string* text); +CC_NOINLINE void LInput_ClearText(struct LInput* w); /* Appends a character to the currently entered text. */ CC_NOINLINE void LInput_Append(struct LInput* w, char c);