From 08e1dd870ef505296e402fb5f2f845797250e314 Mon Sep 17 00:00:00 2001 From: "James R." Date: Mon, 4 Mar 2024 01:16:32 +0000 Subject: [PATCH] Merge branch 'fix-map-plane-crash' into 'master' Fix some R_MapPlane crashes in splitscreen; debugrender_visplanes and debugrender_portal; some multithreading crashes Closes #1032 and #1021 See merge request KartKrew/Kart!1997 --- src/console.c | 4 ++-- src/r_main.cpp | 12 ++++++++---- src/r_plane.cpp | 32 +++++++++++++++++++------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/console.c b/src/console.c index ed127d756..849b936ec 100644 --- a/src/console.c +++ b/src/console.c @@ -1594,6 +1594,8 @@ void CONS_Printf(const char *fmt, ...) vsprintf(txt, fmt, argptr); va_end(argptr); + Lock_state(); + // echo console prints to log file DEBFILE(txt); @@ -1603,8 +1605,6 @@ void CONS_Printf(const char *fmt, ...) CON_LogMessage(txt); - Lock_state(); - // make sure new text is visible con_scrollup = 0; diff --git a/src/r_main.cpp b/src/r_main.cpp index 63a8afe16..377350568 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1647,7 +1647,11 @@ void R_RenderPlayerView(void) { if (top > bot) std::swap(top, bot); - UINT8* p = &screens[0][x + top * vid.width]; + if (top < 0) + top = 0; + if (bot > viewheight-1) + bot = viewheight-1; + UINT8* p = &topleft[x + top * vid.width]; while (top <= bot) { *p = 35; @@ -1664,7 +1668,7 @@ void R_RenderPlayerView(void) INT32 bottom = pl->bottom[pl->minx]; span(pl->minx, top, bottom); span(pl->maxx, pl->top[pl->maxx], pl->bottom[pl->maxx]); - for (INT32 x = pl->minx + 1; x < pl->maxx; ++x) + for (INT32 x = pl->minx + 1; x < std::min(pl->maxx, viewwidth); ++x) { INT32 new_top = pl->top[x]; INT32 new_bottom = pl->bottom[x]; @@ -1698,14 +1702,14 @@ void R_RenderPlayerView(void) INT32 width = (portal->end - portal->start); INT32 i; - for (i = 0; i < width; ++i) + for (i = 0; i < std::min(width, viewwidth); ++i) { INT32 yl = std::max(portal->ceilingclip[i] + 1, 0); INT32 yh = std::min(static_cast(portal->floorclip[i]), viewheight); for (; yl < yh; ++yl) { - screens[0][portal->start + i + (yl * vid.width)] = pal; + topleft[portal->start + i + (yl * vid.width)] = pal; } } diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 3692c943e..5010f7a22 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -128,19 +128,28 @@ static void R_UpdatePlaneRipple(drawspandata_t* ds) ds->planeripple.offset = (leveltime * 140); } +static void R_SetSlopePlaneVectors(drawspandata_t* ds, visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff); + +static bool R_CheckMapPlane(const char* funcname, INT32 y, INT32 x1, INT32 x2) +{ + if (x1 == x2) + return true; + + if (x1 < x2 && x1 >= 0 && x2 < viewwidth && y >= 0 && y < viewheight) + return true; + + CONS_Debug(DBG_RENDER, "%s: x1=%d, x2=%d at y=%d\n", funcname, x1, x2, y); + return false; +} + static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *spanfunc, INT32 y, INT32 x1, INT32 x2, boolean allow_parallel) { angle_t angle, planecos, planesin; fixed_t distance = 0, span; size_t pindex; -#ifdef RANGECHECK - if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight) - I_Error("R_MapPlane: %d, %d at %d", x1, x2, y); -#endif - - if (x1 >= vid.width) - x1 = vid.width - 1; + if (!R_CheckMapPlane(__func__, y, x1, x2)) + return; angle = (ds->currentplane->viewangle + ds->currentplane->plangle)>>ANGLETOFINESHIFT; planecos = FINECOSINE(angle); @@ -216,13 +225,10 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *spanfunc, INT32 y, IN static void R_MapTiltedPlane(drawspandata_t *ds, void(*spanfunc)(drawspandata_t*), INT32 y, INT32 x1, INT32 x2, boolean allow_parallel) { -#ifdef RANGECHECK - if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight) - I_Error("R_MapTiltedPlane: %d, %d at %d", x1, x2, y); -#endif + //ZoneScoped; - if (x1 >= vid.width) - x1 = vid.width - 1; + if (!R_CheckMapPlane(__func__, y, x1, x2)) + return; // Water ripple effect if (ds->planeripple.active)