From b94096ffe193320e81b0f2bb7a58ddf951b53f09 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 10 Nov 2016 05:30:33 +0100 Subject: [PATCH] Crash fixes --- src/r_poly.cpp | 21 ++++++++++++--------- src/r_poly_triangle.cpp | 8 ++++---- src/r_poly_triangle.h | 2 ++ src/r_triangle.cpp | 8 ++++---- src/r_triangle.h | 2 ++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/r_poly.cpp b/src/r_poly.cpp index 01097fe22..1d63630b3 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -129,7 +129,7 @@ void RenderPolyBsp::RenderSubsector(subsector_t *sub) for (uint32_t i = 0; i < sub->numlines; i++) { seg_t *line = &sub->firstline[i]; - if (line->sidedef == NULL || !(line->sidedef->Flags & WALLF_POLYOBJ)) + if (line->sidedef == nullptr || !(line->sidedef->Flags & WALLF_POLYOBJ)) AddLine(line, frontsector); } @@ -237,12 +237,15 @@ void RenderPolyBsp::AddLine(seg_t *line, sector_t *frontsector) if (line->backsector == nullptr) { - wall.SetCoords(line->v1->fPos(), line->v2->fPos(), frontceilz1, frontfloorz1, frontceilz2, frontfloorz2); - wall.TopZ = frontceilz1; - wall.BottomZ = frontfloorz1; - wall.UnpeggedCeil = frontceilz1; - wall.Texpart = side_t::mid; - wall.Render(worldToClip); + if (line->sidedef) + { + wall.SetCoords(line->v1->fPos(), line->v2->fPos(), frontceilz1, frontfloorz1, frontceilz2, frontfloorz2); + wall.TopZ = frontceilz1; + wall.BottomZ = frontfloorz1; + wall.UnpeggedCeil = frontceilz1; + wall.Texpart = side_t::mid; + wall.Render(worldToClip); + } } else { @@ -469,7 +472,7 @@ visstyle_t RenderPolyBsp::GetSpriteVisStyle(AActor *thing, double z) } // get light level - if (fixedcolormap != NULL) + if (fixedcolormap != nullptr) { // fixed map visstyle.BaseColormap = fixedcolormap; visstyle.ColormapNum = 0; @@ -1268,7 +1271,7 @@ void PolyScreenSprite::Render() DTA_FillColor, FillColor, DTA_SpecialColormap, special, DTA_ColorOverlay, overlay.d, - DTA_ColormapStyle, usecolormapstyle ? &colormapstyle : NULL, + DTA_ColormapStyle, usecolormapstyle ? &colormapstyle : nullptr, TAG_DONE); } diff --git a/src/r_poly_triangle.cpp b/src/r_poly_triangle.cpp index a9c54bc74..4b599f931 100644 --- a/src/r_poly_triangle.cpp +++ b/src/r_poly_triangle.cpp @@ -127,7 +127,7 @@ TriVertex PolyTriangleDrawer::shade_vertex(const TriUniforms &uniforms, TriVerte void PolyTriangleDrawer::draw_shaded_triangle(const TriVertex *vert, bool ccw, ScreenPolyTriangleDrawerArgs *args, DrawerThread *thread, void(*drawfunc)(const ScreenPolyTriangleDrawerArgs *, DrawerThread *)) { // Cull, clip and generate additional vertices as needed - TriVertex clippedvert[12]; + TriVertex clippedvert[max_additional_vertices]; int numclipvert; clipedge(vert, clippedvert, numclipvert); @@ -196,7 +196,7 @@ void PolyTriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert // -v.w <= v.z <= v.w // use barycentric weights while clipping vertices - float weights[12 * 3 * 2]; + float weights[max_additional_vertices * 3 * 2]; for (int i = 0; i < 3; i++) { weights[i * 3 + 0] = 0.0f; @@ -220,7 +220,7 @@ void PolyTriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert // Clip against each halfspace float *input = weights; - float *output = weights + 12 * 3; + float *output = weights + max_additional_vertices * 3; int inputverts = 3; int outputverts = 0; for (int p = 0; p < 6; p++) @@ -241,7 +241,7 @@ void PolyTriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert clipdistance[2 * 6 + p] * input[j * 3 + 2]; float t1, t2; - if (!cullhalfspace(clipdistance1, clipdistance2, t1, t2)) + if (!cullhalfspace(clipdistance1, clipdistance2, t1, t2) && outputverts + 1 < max_additional_vertices) { // add t1 vertex for (int k = 0; k < 3; k++) diff --git a/src/r_poly_triangle.h b/src/r_poly_triangle.h index 79c8d4a7a..a392c3c3a 100644 --- a/src/r_poly_triangle.h +++ b/src/r_poly_triangle.h @@ -43,6 +43,8 @@ private: static void queue_arrays(const TriUniforms &uniforms, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, int cliptop, int clipbottom, const uint8_t *texturePixels, int textureWidth, int textureHeight, int solidcolor); + enum { max_additional_vertices = 16 }; + friend class DrawPolyTrianglesCommand; }; diff --git a/src/r_triangle.cpp b/src/r_triangle.cpp index c15817770..ff35cc7da 100644 --- a/src/r_triangle.cpp +++ b/src/r_triangle.cpp @@ -138,7 +138,7 @@ TriVertex TriangleDrawer::shade_vertex(const TriUniforms &uniforms, TriVertex v) void TriangleDrawer::draw_shaded_triangle(const TriVertex *vert, bool ccw, ScreenTriangleDrawerArgs *args, DrawerThread *thread, void(*drawfunc)(const ScreenTriangleDrawerArgs *, DrawerThread *)) { // Cull, clip and generate additional vertices as needed - TriVertex clippedvert[12]; + TriVertex clippedvert[max_additional_vertices]; int numclipvert; clipedge(vert, clippedvert, numclipvert); @@ -207,7 +207,7 @@ void TriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert, in // -v.w <= v.z <= v.w // use barycentric weights while clipping vertices - float weights[12 * 3 * 2]; + float weights[max_additional_vertices * 3 * 2]; for (int i = 0; i < 3; i++) { weights[i * 3 + 0] = 0.0f; @@ -231,7 +231,7 @@ void TriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert, in // Clip against each halfspace float *input = weights; - float *output = weights + 12 * 3; + float *output = weights + max_additional_vertices * 3; int inputverts = 3; int outputverts = 0; for (int p = 0; p < 6; p++) @@ -252,7 +252,7 @@ void TriangleDrawer::clipedge(const TriVertex *verts, TriVertex *clippedvert, in clipdistance[2 * 6 + p] * input[j * 3 + 2]; float t1, t2; - if (!cullhalfspace(clipdistance1, clipdistance2, t1, t2)) + if (!cullhalfspace(clipdistance1, clipdistance2, t1, t2) && outputverts + 1 < max_additional_vertices) { // add t1 vertex for (int k = 0; k < 3; k++) diff --git a/src/r_triangle.h b/src/r_triangle.h index 82b1d2c4d..915f06f59 100644 --- a/src/r_triangle.h +++ b/src/r_triangle.h @@ -106,6 +106,8 @@ private: static void queue_arrays(const TriUniforms &uniforms, const TriVertex *vinput, int vcount, TriangleDrawMode mode, bool ccw, int clipleft, int clipright, const short *cliptop, const short *clipbottom, const uint8_t *texturePixels, int textureWidth, int textureHeight, int solidcolor); + enum { max_additional_vertices = 16 }; + friend class DrawTrianglesCommand; };