- Fix crash when reloading a map

This commit is contained in:
Magnus Norddahl 2018-03-17 00:09:43 +01:00
parent 9a737a0622
commit a2b9a70835
3 changed files with 17 additions and 27 deletions

View File

@ -33,26 +33,15 @@ void PolyCull::CullScene(const PolyClipPlane &portalClipPlane)
ClearSolidSegments(); ClearSolidSegments();
MarkViewFrustum(); MarkViewFrustum();
if (level.LevelName != lastLevelName) // Is this the best way to detect a level change? for (uint32_t sub : PvsSubsectors)
{ SubsectorDepths[sub] = 0xffffffff;
lastLevelName = level.LevelName;
SubsectorDepths.clear();
SubsectorDepths.resize(level.subsectors.Size(), 0xffffffff);
SectorSeen.clear();
SectorSeen.resize(level.sectors.Size());
}
else
{
for (const auto &sub : PvsSectors)
SubsectorDepths[sub->Index()] = 0xffffffff;
SubsectorDepths.resize(level.subsectors.Size(), 0xffffffff); SubsectorDepths.resize(level.subsectors.Size(), 0xffffffff);
for (const auto &sector : SeenSectors) for (uint32_t sector : SeenSectors)
SectorSeen[sector->Index()] = false; SectorSeen[sector] = false;
SectorSeen.resize(level.sectors.Size()); SectorSeen.resize(level.sectors.Size());
}
PvsSectors.clear(); PvsSubsectors.clear();
SeenSectors.clear(); SeenSectors.clear();
NextPvsLineStart = 0; NextPvsLineStart = 0;
@ -125,10 +114,10 @@ void PolyCull::CullSubsector(subsector_t *sub)
FirstSkyHeight = false; FirstSkyHeight = false;
} }
uint32_t subsectorDepth = (uint32_t)PvsSectors.size(); uint32_t subsectorDepth = (uint32_t)PvsSubsectors.size();
// Mark that we need to render this // Mark that we need to render this
PvsSectors.push_back(sub); PvsSubsectors.push_back(sub->Index());
PvsLineStart.push_back(NextPvsLineStart); PvsLineStart.push_back(NextPvsLineStart);
DVector3 viewpos = PolyRenderer::Instance()->Viewpoint.Pos; DVector3 viewpos = PolyRenderer::Instance()->Viewpoint.Pos;
@ -169,7 +158,7 @@ void PolyCull::CullSubsector(subsector_t *sub)
if (!SectorSeen[sub->sector->Index()]) if (!SectorSeen[sub->sector->Index()])
{ {
SectorSeen[sub->sector->Index()] = true; SectorSeen[sub->sector->Index()] = true;
SeenSectors.push_back(sub->sector); SeenSectors.push_back(sub->sector->Index());
} }
SubsectorDepths[sub->Index()] = subsectorDepth; SubsectorDepths[sub->Index()] = subsectorDepth;

View File

@ -36,11 +36,11 @@ public:
return PvsLineVisible[PvsLineStart[subsectorDepth] + lineIndex]; return PvsLineVisible[PvsLineStart[subsectorDepth] + lineIndex];
} }
std::vector<subsector_t *> PvsSectors; std::vector<uint32_t> PvsSubsectors;
double MaxCeilingHeight = 0.0; double MaxCeilingHeight = 0.0;
double MinFloorHeight = 0.0; double MinFloorHeight = 0.0;
std::vector<sector_t *> SeenSectors; std::vector<uint32_t> SeenSectors;
std::vector<bool> SectorSeen; std::vector<bool> SectorSeen;
std::vector<uint32_t> SubsectorDepths; std::vector<uint32_t> SubsectorDepths;

View File

@ -69,8 +69,8 @@ void RenderPolyScene::RenderSectors()
{ {
PolyRenderThread *mainthread = PolyRenderer::Instance()->Threads.MainThread(); PolyRenderThread *mainthread = PolyRenderer::Instance()->Threads.MainThread();
int totalcount = (int)Cull.PvsSectors.size(); int totalcount = (int)Cull.PvsSubsectors.size();
auto subsectors = Cull.PvsSectors.data(); uint32_t *subsectors = Cull.PvsSubsectors.data();
TranslucentObjects.resize(PolyRenderer::Instance()->Threads.NumThreads()); TranslucentObjects.resize(PolyRenderer::Instance()->Threads.NumThreads());
@ -82,7 +82,7 @@ void RenderPolyScene::RenderSectors()
int end = thread->End; int end = thread->End;
for (int i = start; i < end; i++) for (int i = start; i < end; i++)
{ {
RenderSubsector(thread, subsectors[i], i); RenderSubsector(thread, &level.subsectors[subsectors[i]], i);
} }
}, [&](PolyRenderThread *thread) }, [&](PolyRenderThread *thread)
{ {
@ -372,8 +372,9 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
} }
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
for (sector_t *sector : Cull.SeenSectors) for (uint32_t sectorIndex : Cull.SeenSectors)
{ {
sector_t *sector = &level.sectors[sectorIndex];
for (AActor *thing = sector->thinglist; thing != nullptr; thing = thing->snext) for (AActor *thing = sector->thinglist; thing != nullptr; thing = thing->snext)
{ {
DVector2 left, right; DVector2 left, right;