From 879a2bd20afd8cd07089a5fb0909dd17cf6f1109 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 16:39:31 +0100 Subject: [PATCH 1/9] G_GhostTicker/G_ReadMetalTic: type should default to MT_NULL, not -1 This way, if for some reason the ghost has no skin, nothing should spawn at all --- src/g_demo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index 30bc8ca48..63ab4c74f 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -764,7 +764,7 @@ void G_GhostTicker(void) if (xziptic & EZT_THOKMASK) { // Let's only spawn ONE of these per frame, thanks. mobj_t *mobj; - INT32 type = -1; + UINT32 type = MT_NULL; if (g->mo->skin) { skin_t *skin = (skin_t *)g->mo->skin; @@ -1051,7 +1051,7 @@ void G_ReadMetalTic(mobj_t *metal) if (xziptic & EZT_THOKMASK) { // Let's only spawn ONE of these per frame, thanks. mobj_t *mobj; - INT32 type = -1; + UINT32 type = MT_NULL; if (metal->skin) { skin_t *skin = (skin_t *)metal->skin; From d11ba67288ebc27cbb94265c8e1dbcdb5f3fd159 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 16:49:12 +0100 Subject: [PATCH 2/9] G_ReadMetalTic: Make sure all three values for GZT_XYZ are read in the right order --- src/g_demo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/g_demo.c b/src/g_demo.c index 63ab4c74f..c03e2c53f 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -996,7 +996,11 @@ void G_ReadMetalTic(mobj_t *metal) // Read changes from the tic if (ziptic & GZT_XYZ) { - P_TeleportMove(metal, READFIXED(metal_p), READFIXED(metal_p), READFIXED(metal_p)); + // make sure the values are read in the right order + oldmetal.x = READFIXED(metal_p); + oldmetal.y = READFIXED(metal_p); + oldmetal.z = READFIXED(metal_p); + P_TeleportMove(metal, oldmetal.x, oldmetal.y, oldmetal.z); oldmetal.x = metal->x; oldmetal.y = metal->y; oldmetal.z = metal->z; From adb11eec1b3dfe658e55ce93d97f3133a2b04b95 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 17:10:20 +0100 Subject: [PATCH 3/9] dehacked.c: use actual size of descriptions buffers rather than MAXLINELEN, which is way too large --- src/dehacked.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index a6c73e0b4..8450c16e6 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -392,7 +392,7 @@ static void readPlayer(MYFILE *f, INT32 num) // It works down here, though. { INT32 numline = 0; - for (i = 0; i < MAXLINELEN-1; i++) + for (i = 0; (size_t)i < sizeof(description[num].notes)-1; i++) { if (numline < 20 && description[num].notes[i] == '\n') numline++; @@ -1174,7 +1174,7 @@ static void readgametype(MYFILE *f, char *gtname) // It works down here, though. { INT32 numline = 0; - for (i = 0; i < MAXLINELEN-1; i++) + for (i = 0; (size_t)i < sizeof(gtdescription)-1; i++) { if (numline < 20 && gtdescription[i] == '\n') numline++; From 7340442839aa329d870c0e85a91ce2957ba6f0f4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 17:35:14 +0100 Subject: [PATCH 4/9] P_XYMovement: initialise slopemom to all zeros --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 78e0ccd41..98e21544f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1772,7 +1772,7 @@ void P_XYMovement(mobj_t *mo) fixed_t oldx, oldy; // reducing bobbing/momentum on ice when up against walls boolean moved; pslope_t *oldslope = NULL; - vector3_t slopemom; + vector3_t slopemom = {0,0,0}; fixed_t predictedz = 0; I_Assert(mo != NULL); From 8092d30376b8aaa38a4f93736442bece07f26b8d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 17:55:25 +0100 Subject: [PATCH 5/9] Polyobj_rotate and related: change "origin" to vector2_t since all it needs is x/y and not any of the new stuff for vertex_t --- src/p_polyobj.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index cd63f4509..9d293a575 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1039,7 +1039,7 @@ static boolean Polyobj_moveXY(polyobj_t *po, fixed_t x, fixed_t y, boolean check // The formula for this can be found here: // http://www.inversereality.org/tutorials/graphics%20programming/2dtransformations.html // It is, of course, just a vector-matrix multiplication. -static inline void Polyobj_rotatePoint(vertex_t *v, const vertex_t *c, angle_t ang) +static inline void Polyobj_rotatePoint(vertex_t *v, const vector2_t *c, angle_t ang) { vertex_t tmp = *v; @@ -1092,7 +1092,7 @@ static void Polyobj_rotateLine(line_t *ld) } // Causes objects resting on top of the rotating polyobject to 'ride' with its movement. -static void Polyobj_rotateThings(polyobj_t *po, vertex_t origin, angle_t delta, UINT8 turnthings) +static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, UINT8 turnthings) { static INT32 pomovecount = 10000; INT32 x, y; @@ -1172,7 +1172,7 @@ static boolean Polyobj_rotate(polyobj_t *po, angle_t delta, UINT8 turnthings, bo { size_t i; angle_t angle; - vertex_t origin; + vector2_t origin; INT32 hitflags = 0; // don't move bad polyobjects From bb1a2dbba773c5a7da16ff86dc4a156b8c0b3d9b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 18:03:57 +0100 Subject: [PATCH 6/9] sdl/i_main.c: fix wrong placement of #endif for LOGMESSAGES code --- src/sdl/i_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 3eded734f..24841d173 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -191,7 +191,6 @@ int main(int argc, char **argv) left = snprintf(logfilename, sizeof logfilename, "."PATHSEP"%s"PATHSEP, reldir); } -#endif/*LOGMESSAGES*/ strftime(&logfilename[left], sizeof logfilename - left, format, timeinfo); @@ -218,6 +217,7 @@ int main(int argc, char **argv) logstream = fopen("latest-log.txt", "wt+"); #endif/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ } +#endif/*LOGMESSAGES*/ //I_OutputMsg("I_StartupSystem() ...\n"); I_StartupSystem(); From 5349a0bf627085db884be51a67442d5d2827ccaa Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 18:07:12 +0100 Subject: [PATCH 7/9] V_Init: count to NUMSCREENS, not NUMSCREENS+1 (though I can't help thinking this one might have been deliberate somehow?) --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 3ce0e79f5..11381ccea 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3696,7 +3696,7 @@ void V_Init(void) #ifdef DEBUG CONS_Debug(DBG_RENDER, "V_Init done:\n"); - for (i = 0; i < NUMSCREENS+1; i++) + for (i = 0; i < NUMSCREENS; i++) CONS_Debug(DBG_RENDER, " screens[%d] = %x\n", i, screens[i]); #endif } From b11d58aef5c1946a18a8549925cc9a2adfe7e3e0 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 18:49:15 +0100 Subject: [PATCH 8/9] clean up BUGTRAP code in win32/win_main.c to avoid unmatched } (though that said we don't officially care about the win32 folder files anymore) --- src/win32/win_main.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/win32/win_main.c b/src/win32/win_main.c index 8a29f7e18..e1d90881b 100644 --- a/src/win32/win_main.c +++ b/src/win32/win_main.c @@ -643,37 +643,28 @@ int WINAPI WinMain (HINSTANCE hInstance, int nCmdShow) { int Result = -1; - -#if 0 - // Win95 and NT <4 don't have this, so link at runtime. - p_IsDebuggerPresent pfnIsDebuggerPresent = (p_IsDebuggerPresent)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsDebuggerPresent"); -#endif - UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(nCmdShow); -#if 0 -#ifdef BUGTRAP - // Try BugTrap first. - if((!pfnIsDebuggerPresent || !pfnIsDebuggerPresent()) && InitBugTrap()) - Result = HandledWinMain(hInstance); - else { -#endif - // Try Dr MinGW's exception handler. - if (!pfnIsDebuggerPresent || !pfnIsDebuggerPresent()) -#endif - LoadLibraryA("exchndl.dll"); - -#ifndef __MINGW32__ - prevExceptionFilter = SetUnhandledExceptionFilter(RecordExceptionInfo); -#endif - - Result = HandledWinMain(hInstance); +#if 0 + p_IsDebuggerPresent pfnIsDebuggerPresent = (p_IsDebuggerPresent)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsDebuggerPresent"); + if((!pfnIsDebuggerPresent || !pfnIsDebuggerPresent()) +#ifdef BUGTRAP + && !InitBugTrap() +#endif + ) +#endif + { + LoadLibraryA("exchndl.dll"); + } + } +#ifndef __MINGW32__ + prevExceptionFilter = SetUnhandledExceptionFilter(RecordExceptionInfo); +#endif + Result = HandledWinMain(hInstance); #ifdef BUGTRAP - } // BT failure clause. - // This is safe even if BT didn't start. ShutdownBugTrap(); #endif From cb7423b97e4cb720e147458d764d1b29f5604ebe Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 May 2020 19:08:53 +0100 Subject: [PATCH 9/9] sdl/i_main.c: while we're here, split all the logging initialisation code into a separate function, to make main function more clean --- src/sdl/i_main.c | 171 ++++++++++++++++++++++++----------------------- 1 file changed, 88 insertions(+), 83 deletions(-) diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 24841d173..26efd3275 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -103,6 +103,93 @@ static inline VOID MakeCodeWritable(VOID) } #endif +#ifdef LOGMESSAGES +static VOID InitLogging(VOID) +{ + const char *logdir = NULL; + time_t my_time; + struct tm * timeinfo; + const char *format; + const char *reldir; + int left; + boolean fileabs; +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + const char *link; +#endif + + logdir = D_Home(); + + my_time = time(NULL); + timeinfo = localtime(&my_time); + + if (M_CheckParm("-logfile") && M_IsNextParm()) + { + format = M_GetNextParm(); + fileabs = M_IsPathAbsolute(format); + } + else + { + format = "log-%Y-%m-%d_%H-%M-%S.txt"; + fileabs = false; + } + + if (fileabs) + { + strftime(logfilename, sizeof logfilename, format, timeinfo); + } + else + { + if (M_CheckParm("-logdir") && M_IsNextParm()) + reldir = M_GetNextParm(); + else + reldir = "logs"; + + if (M_IsPathAbsolute(reldir)) + { + left = snprintf(logfilename, sizeof logfilename, + "%s"PATHSEP, reldir); + } + else +#ifdef DEFAULTDIR + if (logdir) + { + left = snprintf(logfilename, sizeof logfilename, + "%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir); + } + else +#endif/*DEFAULTDIR*/ + { + left = snprintf(logfilename, sizeof logfilename, + "."PATHSEP"%s"PATHSEP, reldir); + } + + strftime(&logfilename[left], sizeof logfilename - left, + format, timeinfo); + } + + M_MkdirEachUntil(logfilename, + M_PathParts(logdir) - 1, + M_PathParts(logfilename) - 1, 0755); + +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + logstream = fopen(logfilename, "w"); +#ifdef DEFAULTDIR + if (logdir) + link = va("%s/"DEFAULTDIR"/latest-log.txt", logdir); + else +#endif/*DEFAULTDIR*/ + link = "latest-log.txt"; + unlink(link); + if (symlink(logfilename, link) == -1) + { + I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno)); + } +#else/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ + logstream = fopen("latest-log.txt", "wt+"); +#endif/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ +} +#endif + /** \brief The main function @@ -121,7 +208,6 @@ int SDL_main(int argc, char **argv) int main(int argc, char **argv) #endif { - const char *logdir = NULL; myargc = argc; myargv = argv; /// \todo pull out path to exe from this string @@ -135,88 +221,7 @@ int main(int argc, char **argv) #ifdef LOGMESSAGES if (!M_CheckParm("-nolog")) - { - time_t my_time; - struct tm * timeinfo; - const char *format; - const char *reldir; - int left; - boolean fileabs; -#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) - const char *link; -#endif - - logdir = D_Home(); - - my_time = time(NULL); - timeinfo = localtime(&my_time); - - if (M_CheckParm("-logfile") && M_IsNextParm()) - { - format = M_GetNextParm(); - fileabs = M_IsPathAbsolute(format); - } - else - { - format = "log-%Y-%m-%d_%H-%M-%S.txt"; - fileabs = false; - } - - if (fileabs) - { - strftime(logfilename, sizeof logfilename, format, timeinfo); - } - else - { - if (M_CheckParm("-logdir") && M_IsNextParm()) - reldir = M_GetNextParm(); - else - reldir = "logs"; - - if (M_IsPathAbsolute(reldir)) - { - left = snprintf(logfilename, sizeof logfilename, - "%s"PATHSEP, reldir); - } - else -#ifdef DEFAULTDIR - if (logdir) - { - left = snprintf(logfilename, sizeof logfilename, - "%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir); - } - else -#endif/*DEFAULTDIR*/ - { - left = snprintf(logfilename, sizeof logfilename, - "."PATHSEP"%s"PATHSEP, reldir); - } - - strftime(&logfilename[left], sizeof logfilename - left, - format, timeinfo); - } - - M_MkdirEachUntil(logfilename, - M_PathParts(logdir) - 1, - M_PathParts(logfilename) - 1, 0755); - -#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) - logstream = fopen(logfilename, "w"); -#ifdef DEFAULTDIR - if (logdir) - link = va("%s/"DEFAULTDIR"/latest-log.txt", logdir); - else -#endif/*DEFAULTDIR*/ - link = "latest-log.txt"; - unlink(link); - if (symlink(logfilename, link) == -1) - { - I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno)); - } -#else/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ - logstream = fopen("latest-log.txt", "wt+"); -#endif/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ - } + InitLogging(); #endif/*LOGMESSAGES*/ //I_OutputMsg("I_StartupSystem() ...\n");