From b0e968e3c376300aa92eb569c7e6cafaa6a7aa04 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 15:54:53 +0100 Subject: [PATCH 1/8] raise version number to 9.2 --- src/doomdef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 1a4daf21d..492fa1185 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -107,8 +107,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v9.1" -#define VERSIONSTRINGW L"Saturn v9.1" +#define VERSIONSTRING "Saturn v9.2" +#define VERSIONSTRINGW L"Saturn v9.2" #define SATURN_TESTING // comment out for saturn release builds! From 982fff959f62a357540fe339c03f93b3fb44b511 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 18:31:01 +0100 Subject: [PATCH 2/8] blua: attempt emergency garbo collection on file io operations if they fail ports of https://github.com/lua/lua/commit/e885dee5ab4dbee2457ee2023340e848fdabdef9 and https://github.com/lua/lua/commit/3d838f635cc81ec3332f9a904992db1c6d8a46ad prevents massive memory leaks and other issues due to faulty lua scripts --- src/blua/lauxlib.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ src/blua/lauxlib.h | 2 ++ src/blua/liolib.c | 38 +++++++++++++++++++++-------------- 3 files changed, 75 insertions(+), 15 deletions(-) diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index e91faa182..905123e29 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -93,6 +93,56 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { /* }====================================================== */ +/* +** {====================================================== +** 'luaL_resourcetryagain' +** This function uses 'errno' to check whether the last error was +** related to lack of resources (e.g., not enough memory or too many +** open files). If so, the function performs a full garbage collection +** to try to release resources, and then it returns 1 to signal to +** the caller that it is worth trying again the failed operation. +** Otherwise, it returns 0. Because error codes are not ANSI C, the +** code must handle any combination of error codes that are defined. +** ======================================================= +*/ + +LUALIB_API int luaL_resourcetryagain (lua_State *L) { + +/* these are the resource-related errors in Linux */ +#if defined(EMFILE) || defined(ENFILE) || defined(ENOMEM) + +#if !defined(EMFILE) /* too many open files in the process */ +#define EMFILE -1 /* if not defined, use an impossible value */ +#endif + +#if !defined(ENFILE) /* too many open files in the system */ +#define ENFILE -1 +#endif + +#if !defined(ENOMEM) /* not enough memory */ +#define ENOMEM -1 +#endif + + if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) { + lua_gc(L, LUA_GCCOLLECT, 0); /* try to release resources with a full GC */ + return 1; /* signal to try again the creation */ + } + +#endif + + return 0; /* else, asume errors are not due to lack of resources */ + +} + +/* }====================================================== */ + + +/* +** {====================================================== +** Userdata's metatable manipulation +** ======================================================= +*/ + LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, const char *const lst[]) { const char *name = (def) ? luaL_optstring(L, narg, def) : diff --git a/src/blua/lauxlib.h b/src/blua/lauxlib.h index befdae303..c5de212c8 100644 --- a/src/blua/lauxlib.h +++ b/src/blua/lauxlib.h @@ -95,6 +95,8 @@ LUALIB_API FUNCREPORT int (luaL_error) (lua_State *L, const char *fmt, ...); LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, const char *const lst[]); +LUALIB_API int (luaL_resourcetryagain) (lua_State *L); + LUALIB_API int (luaL_ref) (lua_State *L, int t); LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); diff --git a/src/blua/liolib.c b/src/blua/liolib.c index 929937e2e..2cd8dd481 100644 --- a/src/blua/liolib.c +++ b/src/blua/liolib.c @@ -58,12 +58,6 @@ static int pushresult (lua_State *L, int i, const char *filename) { } -static void fileerror (lua_State *L, int arg, const char *filename) { - lua_pushfstring(L, "%s: %s", filename, strerror(errno)); - luaL_argerror(L, arg, lua_tostring(L, -1)); -} - - #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) @@ -165,6 +159,24 @@ static int StartsWith(const char *a, const char *b) // this is wolfs being lazy return 0; } +/* +** Equivalent to 'fopen', but if it fails due to a lack of resources +** (see 'luaL_resourcetryagain'), do an "emergency" garbage collection to try +** to close some files and then tries to open the file again. +*/ +static FILE *trytoopen (lua_State *L, const char *path, const char *mode) { + FILE *f = fopen(path, mode); + if (f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ + f = fopen(path, mode); /* try to open again */ + return f; +} + +static void opencheck (lua_State *L, const char *fname, const char *mode) { + FILE **p = newfile(L); + *p = trytoopen(L, fname, mode); + if (l_unlikely(*p == NULL)) + luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); +} static int io_open(lua_State *L) { @@ -212,7 +224,7 @@ static int io_open(lua_State *L) } pf = newfile(L); - *pf = fopen(destFilename, mode); + *pf = trytoopen(L, destFilename, mode); return (*pf == NULL) ? pushresult(L, 0, filename) : 1; } @@ -220,6 +232,8 @@ static int io_open(lua_State *L) static int io_tmpfile (lua_State *L) { FILE **pf = newfile(L); *pf = tmpfile(); + if (*pf == NULL && luaL_resourcetryagain(L)) /* resource failure? */ + *pf = tmpfile(); /* try to open again */ return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; } @@ -238,10 +252,7 @@ static int g_iofile (lua_State *L, int f, const char *mode) { if (!lua_isnoneornil(L, 1)) { const char *filename = lua_tostring(L, 1); if (filename) { - FILE **pf = newfile(L); - *pf = fopen(filename, mode); - if (l_unlikely(*pf == NULL)) - fileerror(L, 1, filename); + opencheck(L, filename, mode); } else { tofile(L); /* check that it's a valid file handle */ @@ -290,10 +301,7 @@ static int io_lines (lua_State *L) { } else { const char *filename = luaL_checkstring(L, 1); - FILE **pf = newfile(L); - *pf = fopen(filename, "r"); - if (l_unlikely(*pf == NULL)) - fileerror(L, 1, filename); + opencheck(L, filename, "r"); aux_lines(L, lua_gettop(L), 1); return 1; } From f283d3ca4378aae6df406f57dc855610aeeb6bbf Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 18:40:14 +0100 Subject: [PATCH 3/8] suppress wrong "-Warray-bounds" warning in G_DeviceLEDTick newer gcc does this for whatever reason, its fine splitscreen will never call this out of its bounds --- src/g_input.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/g_input.c b/src/g_input.c index 424a749bd..5f3333fa9 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -714,8 +714,13 @@ void G_DeviceLEDTick(void) newcolor = G_GetSkinColorForGamepad(i); + // compiler be absolutely tripping + // delet this if this gets fixed within gcc +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" if (curcolor[i] == newcolor) // dont update if same colour continue; +#pragma GCC diagnostic pop G_SetPlayerGamepadIndicatorColor(i, newcolor); curcolor[i] = newcolor; From 0e0a690e3cd9e610d4074d964467394fdb796b05 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 2 Dec 2025 20:39:19 +0300 Subject: [PATCH 4/8] Print a warning when luaL_resourcetryagain force triggers garbage collector --- src/blua/lauxlib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index 905123e29..5fb454d5e 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -124,6 +124,7 @@ LUALIB_API int luaL_resourcetryagain (lua_State *L) { #endif if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) { + CONS_Alert(CONS_WARNING, "%s, force calling lua garbage collector\n", strerror(errno)); lua_gc(L, LUA_GCCOLLECT, 0); /* try to release resources with a full GC */ return 1; /* signal to try again the creation */ } From 64152eea0dcaad79752b5d23c2ba6ea31e7660ef Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 2 Dec 2025 20:59:27 +0300 Subject: [PATCH 5/8] Fix few possible multithreading bugs related to ReplayNamesLoadThread --- src/m_menu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index b1935e37d..8f50a9633 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3966,6 +3966,7 @@ menudemo_t *demolist = NULL; // Replays that that have been checked to match wit // Locked behind Lock_search_state menudemo_t *demolist_all = NULL; // All replays +size_t demolist_all_size = 0; boolean replaynamesloaded = false; #ifdef HAVE_THREADS @@ -3998,14 +3999,14 @@ static void ReplayNamesLoadThread(void* userdata) { Lock_search_state(); - size_t demolist_all_size = sizedirmenu; - menudemo_t *demolist_all_local = (menudemo_t*)malloc(sizeof(menudemo_t)*sizedirmenu); - memcpy(demolist_all_local, demolist_all, sizeof(menudemo_t)*sizedirmenu); + size_t demolist_all_size_local = demolist_all_size; + menudemo_t *demolist_all_local = (menudemo_t*)malloc(sizeof(menudemo_t)*demolist_all_size_local); + memcpy(demolist_all_local, demolist_all, sizeof(menudemo_t)*demolist_all_size_local); char *replaydirpath = (char*)userdata; Unlock_search_state(); - for (size_t i = 0; i < demolist_all_size; ++i) + for (size_t i = 0; i < demolist_all_size_local; ++i) { if (demolist_all_local[i].type != MD_SUBDIR) { @@ -4021,9 +4022,9 @@ static void ReplayNamesLoadThread(void* userdata) Lock_search_state(); - if (fastcmp(menupath, replaydirpath)) + if (fastcmp(menupath, replaydirpath) && demolist_all) { - memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*sizedirmenu); + memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*demolist_all_size); replaynamesloaded = true; } @@ -4157,6 +4158,7 @@ static void PrepReplayList(boolean reset) Z_Free(demolist_all); demolist_all = Z_Calloc(sizeof(menudemo_t) * sizedirmenu, PU_STATIC, NULL); + demolist_all_size = sizedirmenu; for (i = 0; i < sizedirmenu; i++) { From 04458f18f867927bd19a6233d871eb5dc21ce664 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 19:42:54 +0100 Subject: [PATCH 6/8] m_menu: fix splitscreen players being unable to change the names from player setup smol oversight :blobcatpats: --- src/m_menu.c | 55 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 8f50a9633..3fbe80aec 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -197,7 +197,30 @@ static INT32 vidm_column_size; #define SETUPM_IP_MAXSIZE ((28-1)*8) static char setupm_ip[64]; static textinput_t setupm_input_ip; -static UINT8 setupm_pselect = 1; + + +static fixed_t multi_tics; +static state_t *multi_state; + +// this is set before entering the MultiPlayer setup menu, +// for either player 1 or 2 +static char setupm_name[MAXPLAYERNAME+1]; +static textinput_t setupm_input; +static player_t *setupm_player; +static consvar_t *setupm_cvskin; +static consvar_t *setupm_cvcolor; +static consvar_t *setupm_cvname; +static UINT8 setupm_skinxpos; +static INT32 setupm_fakeskin; +static INT32 setupm_fakecolor; +static UINT8 setupm_pselect = 1; + +//variables used for other skin select menus +static UINT8 setupm_skinypos; +static INT32 setupm_skinselect; +static boolean setupm_skinlockedselect; + +static UINT8 setupm_playernum; //brap // // PROTOTYPES @@ -895,7 +918,7 @@ static void M_CheckStringItem(void) // special case: name input, cap it to prevent writing outside the textbox // kinda ugly but itll work - if (cv == &cv_playername) + if (cv == setupm_cvname) M_TextInputInit(&menuinput, menu_text_input_buf, MAXPLAYERNAME +1); else M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); @@ -7841,28 +7864,6 @@ static void M_HandleConnectIP(INT32 choice) // ======================== // Tails 03-02-2002 -static fixed_t multi_tics; -static state_t *multi_state; - -// this is set before entering the MultiPlayer setup menu, -// for either player 1 or 2 -static char setupm_name[MAXPLAYERNAME+1]; -static textinput_t setupm_input; -static player_t *setupm_player; -static consvar_t *setupm_cvskin; -static consvar_t *setupm_cvcolor; -static consvar_t *setupm_cvname; -static UINT8 setupm_skinxpos; -static INT32 setupm_fakeskin; -static INT32 setupm_fakecolor; - -//variables used for other skin select menus -static UINT8 setupm_skinypos; -static INT32 setupm_skinselect; -static boolean setupm_skinlockedselect; - -static UINT8 setupm_playernum; //brap - #define SELECTEDSTATSCOUNT skinstatscount[setupm_skinxpos][setupm_skinypos] #define LASTSELECTEDSTAT skinstats[setupm_skinxpos][setupm_skinypos][skinstatscount[setupm_skinxpos][setupm_skinypos]] @@ -8920,9 +8921,6 @@ static void M_DoSetupMultiPlayer(UINT8 pnum) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics*FRACUNIT; - M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); - M_TextInputSetString(&setupm_input, cv_playername.string); - switch (pnum) { case 1: @@ -8951,6 +8949,9 @@ static void M_DoSetupMultiPlayer(UINT8 pnum) break; } + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, setupm_cvname->string); + setupm_skinxpos = 4; setupm_skinypos = 0; setupm_skinlockedselect = false; From d4f58a885bf1ee5a25ffcd6328143dff8fed72eb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 20:07:46 +0100 Subject: [PATCH 7/8] add toggle to let console prints show in main menus if you want this for some reason --- src/console.c | 5 ++++- src/console.h | 1 + src/m_menudefs.c | 9 +++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/console.c b/src/console.c index d3c2623f4..92c9dabc4 100644 --- a/src/console.c +++ b/src/console.c @@ -169,6 +169,8 @@ static CV_PossibleValue_t menuhighlight_cons_t[] = }; consvar_t cons_menuhighlight = {"menuhighlight", "Gametype Default", CV_SAVE, menuhighlight_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cons_consoleprintinmenu = {"consoleprintinmenu", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static void CON_Print(char *msg); // @@ -426,6 +428,7 @@ void CON_Init(void) CV_RegisterVar(&cons_backpic); CV_RegisterVar(&cons_backcolor); CV_RegisterVar(&cons_menuhighlight); + CV_RegisterVar(&cons_consoleprintinmenu); COM_AddCommand("bind", CONS_Bind_f); } else @@ -1590,7 +1593,7 @@ void CON_Drawer(void) if (con_curlines > 0) CON_DrawConsole(); else if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_CUTSCENE || gamestate == GS_CREDITS - || gamestate == GS_VOTING || gamestate == GS_EVALUATION || gamestate == GS_WAITINGPLAYERS) + || gamestate == GS_VOTING || gamestate == GS_EVALUATION || gamestate == GS_WAITINGPLAYERS || (cons_consoleprintinmenu.value && gamestate == GS_TITLESCREEN)) CON_DrawHudlines(); Unlock_state(); diff --git a/src/console.h b/src/console.h index 79af2e48f..4245f8d31 100644 --- a/src/console.h +++ b/src/console.h @@ -36,6 +36,7 @@ extern INT32 con_destlines; extern UINT32 con_scalefactor; // console text scale factor extern consvar_t cons_backcolor, cons_menuhighlight; +extern consvar_t cons_consoleprintinmenu; extern UINT8 *yellowmap, *purplemap, *greenmap, *bluemap, *graymap, *redmap, *orangemap,\ *skymap, *goldmap, *lavendermap, *teamap, *steelmap, *pinkmap, *brownmap, *peachmap; diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 16991f629..7121f2065 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1325,13 +1325,14 @@ static menuitem_t OP_HUDOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Menu Highlights", &cons_menuhighlight, 95}, // highlight info - (GOOD HIGHLIGHT, WARNING HIGHLIGHT) - 110 (see M_DrawHUDOptions) - {IT_STRING | IT_CVAR, NULL, "Console Text Size", &cv_constextsize, 120}, + {IT_STRING | IT_CVAR, NULL, "Console Text Size", &cv_constextsize, 120}, + {IT_STRING | IT_CVAR, NULL, "Show Console Prints in Menu",&cons_consoleprintinmenu, 130}, - {IT_STRING | IT_CVAR, NULL, "Show Track Addon Name", &cv_showtrackaddon, 135}, + {IT_STRING | IT_CVAR, NULL, "Show Track Addon Name", &cv_showtrackaddon, 145}, - {IT_STRING | IT_CVAR, NULL, "Show All Maps", &cv_showallmaps, 145}, + {IT_STRING | IT_CVAR, NULL, "Show All Maps", &cv_showallmaps, 155}, - {IT_STRING | IT_CVAR, NULL, "2D character select", &cv_skinselectmenu, 155}, + {IT_STRING | IT_CVAR, NULL, "2D character select", &cv_skinselectmenu, 165}, }; static menuitem_t OP_CamOptionsMenu[] = From b273bc3ca88e4647dc8da8b2b9b0bdb923aa6c3c Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 2 Dec 2025 22:11:54 +0300 Subject: [PATCH 8/8] Hide localskins menus immediately when option is changed @Alug :blobhug: --- src/d_netcmd.c | 2 +- src/m_menu.c | 5 +++++ src/m_menu.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 420a20ab2..00760e4a4 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -270,7 +270,7 @@ consvar_t cv_skin4 = {"skin4", DEFAULTSKIN4, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Sk // haha I've beaten you now, ONLINE consvar_t cv_localskin = {"internal___localskin", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showlocalskinmenus = {"showlocalskinmenus", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showlocalskinmenus = {"showlocalskinmenus", "Yes", CV_SAVE|CV_CALL, CV_YesNo, ShowLocalskinMenu_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/m_menu.c b/src/m_menu.c index 3fbe80aec..031c64447 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -798,6 +798,11 @@ static void Splitplayers_OnChange(void) setupm_pselect = 1; } +void ShowLocalskinMenu_Onchange(void) +{ + OP_MainMenu[localskin].status = (!cv_showlocalskinmenus.value) ? (IT_DISABLED) : (IT_CALL|IT_STRING); +} + // current menudef menu_t *currentMenu = &MainDef; diff --git a/src/m_menu.h b/src/m_menu.h index f3e155b46..62f66f177 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -301,6 +301,8 @@ void SaturnHud_menu_Onchange(void); void GameFocus_menu_Onchange (void); +void ShowLocalskinMenu_Onchange(void); + #ifdef HWRENDER void M_UpdateOGLMenu(void); #endif