From c5db5dff997e738a855013e7ad3daed2907e66ad Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 16 Jul 2016 12:45:49 +0200 Subject: [PATCH] - fixed a crash when initializing the GL portal data for an incomplete or inactive portal. Also did a bit of cleanup on this code, the 'delta' member was never used. --- src/gl/data/gl_data.h | 5 ++- src/gl/data/gl_portaldata.cpp | 65 ++++++++++++++++------------------- src/gl/scene/gl_portal.h | 2 +- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/gl/data/gl_data.h b/src/gl/data/gl_data.h index 3e43408dd4..f1bc27ee4d 100644 --- a/src/gl/data/gl_data.h +++ b/src/gl/data/gl_data.h @@ -56,9 +56,8 @@ struct FPortal struct FGLLinePortal { - // defines the complete span of this portal - vertex_t *v1, *v2; // vertices, from v1 to v2 - DVector2 delta; // precalculated v2 - v1 for side checking + // defines the complete span of this portal, if this is of type PORTT_LINKED. + vertex_t *v1 = nullptr, *v2 = nullptr; // vertices, from v1 to v2 TArray lines; int validcount = 0; }; diff --git a/src/gl/data/gl_portaldata.cpp b/src/gl/data/gl_portaldata.cpp index 2635c9a2e5..847bf6f619 100644 --- a/src/gl/data/gl_portaldata.cpp +++ b/src/gl/data/gl_portaldata.cpp @@ -443,54 +443,49 @@ void gl_InitPortals() tempindex[i] = glLinePortals.Size(); line_t *pSrcLine = linePortals[i].mOrigin; line_t *pLine = linePortals[i].mDestination; - FGLLinePortal glport; - - glport.v1 = pLine->v1; - glport.v2 = pLine->v2; - glport.delta = { 0, 0 }; + FGLLinePortal &glport = glLinePortals[glLinePortals.Reserve(1)]; glport.lines.Push(&linePortals[i]); - glLinePortals.Push(glport); // We cannot do this grouping for non-linked portals because they can be changed at run time. - if (linePortals[i].mType == PORTT_LINKED) - do + if (linePortals[i].mType == PORTT_LINKED && pLine != nullptr) { - // now collect all other colinear lines connected to this one. We run this loop as long as it still finds a match - gotsome = false; - for (unsigned j = 0; j < linePortals.Size(); j++) + glport.v1 = pLine->v1; + glport.v2 = pLine->v2; + do { - if (tempindex[j] == -1) + // now collect all other colinear lines connected to this one. We run this loop as long as it still finds a match + gotsome = false; + for (unsigned j = 0; j < linePortals.Size(); j++) { - line_t *pSrcLine2 = linePortals[j].mOrigin; - line_t *pLine2 = linePortals[j].mDestination; - // angular precision is intentionally reduced to 32 bit BAM to account for precision problems (otherwise many not perfectly horizontal or vertical portals aren't found here.) - unsigned srcang = pSrcLine->Delta().Angle().BAMs(); - unsigned dstang = pLine->Delta().Angle().BAMs(); - if ((pSrcLine->v2 == pSrcLine2->v1 && pLine->v1 == pLine2->v2) || - (pSrcLine->v1 == pSrcLine2->v2 && pLine->v2 == pLine2->v1)) + if (tempindex[j] == -1) { - // The line connects, now check the translation - unsigned srcang2 = pSrcLine2->Delta().Angle().BAMs(); - unsigned dstang2 = pLine2->Delta().Angle().BAMs(); - if (srcang == srcang2 && dstang == dstang2) + line_t *pSrcLine2 = linePortals[j].mOrigin; + line_t *pLine2 = linePortals[j].mDestination; + // angular precision is intentionally reduced to 32 bit BAM to account for precision problems (otherwise many not perfectly horizontal or vertical portals aren't found here.) + unsigned srcang = pSrcLine->Delta().Angle().BAMs(); + unsigned dstang = pLine->Delta().Angle().BAMs(); + if ((pSrcLine->v2 == pSrcLine2->v1 && pLine->v1 == pLine2->v2) || + (pSrcLine->v1 == pSrcLine2->v2 && pLine->v2 == pLine2->v1)) { - // The lines connect and both source and destination are colinear, so this is a match - gotsome = true; - tempindex[j] = tempindex[i]; - if (pLine->v1 == pLine2->v2) glLinePortals[tempindex[i]].v1 = pLine2->v1; - else glLinePortals[tempindex[i]].v2 = pLine2->v2; - glLinePortals[tempindex[i]].lines.Push(&linePortals[j]); + // The line connects, now check the translation + unsigned srcang2 = pSrcLine2->Delta().Angle().BAMs(); + unsigned dstang2 = pLine2->Delta().Angle().BAMs(); + if (srcang == srcang2 && dstang == dstang2) + { + // The lines connect and both source and destination are colinear, so this is a match + gotsome = true; + tempindex[j] = tempindex[i]; + if (pLine->v1 == pLine2->v2) glport.v1 = pLine2->v1; + else glport.v2 = pLine2->v2; + glport.lines.Push(&linePortals[j]); + } } } } - } - } while (gotsome); + } while (gotsome); + } } } - for (auto glport : glLinePortals) - { - glport.delta = glport.v2->fPos() - glport.v1->fPos(); - } linePortalToGL.Resize(linePortals.Size()); for (unsigned i = 0; i < linePortals.Size(); i++) { diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index 9ebfe083bc..7b9f896db4 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -195,7 +195,7 @@ struct GLLinePortal : public GLPortal GLLinePortal(FGLLinePortal *line) { - if (line->lines[0]->mType != PORTT_LINKED) + if (line->lines[0]->mType != PORTT_LINKED || line->v1 == nullptr) { // For non-linked portals we must check the actual linedef. line_t *lline = line->lines[0]->mDestination;