- 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.

This commit is contained in:
Christoph Oelckers 2016-07-16 12:45:49 +02:00
parent a2f56b6ef5
commit c5db5dff99
3 changed files with 33 additions and 39 deletions

View file

@ -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<FLinePortal *> lines;
int validcount = 0;
};

View file

@ -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++)
{

View file

@ -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;