[client] overlay: fix race on startup that caused a segfault

Fixes #1065
This commit is contained in:
Geoffrey McRae 2023-03-30 14:58:19 +11:00
parent 0ee5751b3a
commit 996e1b2f7a
2 changed files with 16 additions and 4 deletions

View File

@ -656,8 +656,6 @@ MsgBoxHandle app_msgBox(const char * caption, const char * fmt, ...)
MsgBoxHandle handle = overlayMsg_show(caption, NULL, NULL, fmt, args); MsgBoxHandle handle = overlayMsg_show(caption, NULL, NULL, fmt, args);
va_end(args); va_end(args);
core_updateOverlayState();
return handle; return handle;
} }
@ -669,8 +667,6 @@ MsgBoxHandle app_confirmMsgBox(const char * caption,
MsgBoxHandle handle = overlayMsg_show(caption, callback, opaque, fmt, args); MsgBoxHandle handle = overlayMsg_show(caption, callback, opaque, fmt, args);
va_end(args); va_end(args);
core_updateOverlayState();
return handle; return handle;
} }

View File

@ -27,6 +27,7 @@
#include "common/stringlist.h" #include "common/stringlist.h"
#include "../main.h" #include "../main.h"
#include "../core.h"
#include <string.h> #include <string.h>
@ -41,6 +42,8 @@ struct Msg
struct MsgState struct MsgState
{ {
bool initialized;
bool updateOverlayState;
struct ll * messages; struct ll * messages;
}; };
@ -53,6 +56,7 @@ static void msg_earlyInit(void)
static bool msg_init(void ** udata, const void * params) static bool msg_init(void ** udata, const void * params)
{ {
l_msg.initialized = true;
return true; return true;
} }
@ -70,6 +74,7 @@ static void msg_free(void * udata)
while(ll_shift(l_msg.messages, (void **)&msg)) while(ll_shift(l_msg.messages, (void **)&msg))
freeMsg(msg); freeMsg(msg);
ll_free(l_msg.messages); ll_free(l_msg.messages);
l_msg.initialized = false;
} }
static bool msg_needsOverlay(void * udata) static bool msg_needsOverlay(void * udata)
@ -181,6 +186,12 @@ struct LG_OverlayOps LGOverlayMsg =
bool overlayMsg_modal(void) bool overlayMsg_modal(void)
{ {
if (l_msg.updateOverlayState)
{
core_updateOverlayState();
l_msg.updateOverlayState = false;
}
return ll_count(l_msg.messages) > 0; return ll_count(l_msg.messages) > 0;
} }
@ -221,6 +232,11 @@ MsgBoxHandle overlayMsg_show(
ll_push(l_msg.messages, msg); ll_push(l_msg.messages, msg);
app_invalidateOverlay(false); app_invalidateOverlay(false);
if (l_msg.initialized)
core_updateOverlayState();
else
l_msg.updateOverlayState = true;
return (MsgBoxHandle)msg; return (MsgBoxHandle)msg;
} }