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)

This commit is contained in:
UnknownShadow200 2021-04-20 07:36:17 +10:00
parent 7639e8924c
commit 90ff11fe98
5 changed files with 9 additions and 19 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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 */

View File

@ -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) {

View File

@ -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);