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
This commit is contained in:
James R. 2024-03-04 01:16:32 +00:00
commit 235987b895
3 changed files with 26 additions and 19 deletions

View file

@ -1512,6 +1512,8 @@ void CONS_Printf(const char *fmt, ...)
vsprintf(txt, fmt, argptr);
va_end(argptr);
Lock_state();
// echo console prints to log file
DEBFILE(txt);
@ -1521,8 +1523,6 @@ void CONS_Printf(const char *fmt, ...)
CON_LogMessage(txt);
Lock_state();
// make sure new text is visible
con_scrollup = 0;

View file

@ -1617,7 +1617,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;
@ -1634,7 +1638,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];
@ -1668,14 +1672,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<INT32>(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;
}
}

View file

@ -126,6 +126,18 @@ static void R_UpdatePlaneRipple(drawspandata_t* ds)
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)
{
ZoneScoped;
@ -133,13 +145,8 @@ static void R_MapPlane(drawspandata_t *ds, spandrawfunc_t *spanfunc, INT32 y, IN
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 +223,9 @@ 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)
{
ZoneScoped;
#ifdef RANGECHECK
if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y >= viewheight || y < 0)
I_Error("R_MapTiltedPlane: %d, %d at %d", x1, x2, y);
#endif
if (x1 >= vid.width)
x1 = vid.width - 1;
if (!R_CheckMapPlane(__func__, y, x1, x2))
return;
// Water ripple effect
if (ds->planeripple.active)