From da1762ac2ca5a485e2a6141f3497adea90ba0416 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 27 Jul 2016 16:27:40 +0200 Subject: [PATCH] - fixed: DoSetMapSection could cause a stack overflow on large maps. Made it iterative instead of recursive to avoid that. --- src/gl/data/gl_setup.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index fb9c2252f..04ed4c427 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -69,26 +69,34 @@ void InitGLRMapinfoData(); // // //========================================================================== +static TArray MapSectionCollector; static void DoSetMapSection(subsector_t *sub, int num) { + MapSectionCollector.Resize(1); + MapSectionCollector[0] = sub; sub->mapsection = num; - - for(DWORD i=0;inumlines;i++) + for (unsigned a = 0; a < MapSectionCollector.Size(); a++) { - seg_t * seg = sub->firstline + i; - - if (seg->PartnerSeg) + sub = MapSectionCollector[a]; + for (DWORD i = 0; i < sub->numlines; i++) { - subsector_t * sub2 = seg->PartnerSeg->Subsector; + seg_t * seg = sub->firstline + i; - if (sub2->mapsection != num) + if (seg->PartnerSeg) { - assert(sub2->mapsection == 0); - DoSetMapSection(sub2, num); + subsector_t * sub2 = seg->PartnerSeg->Subsector; + + if (sub2->mapsection != num) + { + assert(sub2->mapsection == 0); + sub2->mapsection = num; + MapSectionCollector.Push(sub2); + } } } } + MapSectionCollector.Clear(); } //==========================================================================