From d00ad6043716457ed0162928a4e19faf45816a43 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 12:39:50 +0200 Subject: [PATCH] - fixed a few issues pointed out by the assert in the TArray [] operator. --- src/maploader/renderinfo.cpp | 2 +- src/p_saveg.cpp | 2 +- src/r_data/r_sections.cpp | 15 +++++++++++++++ src/r_data/r_translate.h | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/maploader/renderinfo.cpp b/src/maploader/renderinfo.cpp index 32ec955ac1..4faeb0eabe 100644 --- a/src/maploader/renderinfo.cpp +++ b/src/maploader/renderinfo.cpp @@ -709,7 +709,7 @@ void MapLoader::InitRenderInfo() PrepareSectorData(); InitVertexData(); FloodSectorStacks(); - TArray checkmap(Level->vertexes.Size()); + TArray checkmap(Level->vertexes.Size(), true); memset(checkmap.Data(), -1, sizeof(int)*Level->vertexes.Size()); for(auto &sec : Level->sectors) { diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 2ff6b9bf90..adcd093fda 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -374,7 +374,7 @@ FSerializer &FLevelLocals::SerializeSubsectors(FSerializer &arc, const char *key auto numsubsectors = subsectors.Size(); if (arc.isWriting()) { - TArray encoded(1 + (numsubsectors + 5) / 6); + TArray encoded(1 + (numsubsectors + 5) / 6, true); int p = 0; for (unsigned i = 0; i < numsubsectors; i += 6) { diff --git a/src/r_data/r_sections.cpp b/src/r_data/r_sections.cpp index 998945aa64..7ffe3cf0f4 100644 --- a/src/r_data/r_sections.cpp +++ b/src/r_data/r_sections.cpp @@ -803,6 +803,21 @@ public: sub.section = bestfit; } } + + // Set all empty sectors' initial index to 0, so that we do not have to range-check each access. + for (unsigned i = 0; i < Level->sectors.Size(); i++) + { + if (Level->sections.firstSectionForSectorPtr[i] < 0) + { + Level->sections.firstSectionForSectorPtr[i] = 0; + if (Level->sections.numberOfSectionForSectorPtr[i] > 0) + { + // This should never happen. + Printf("Warning: Sector %d has a non-empty section list with no address\n", i); + Level->sections.numberOfSectionForSectorPtr = 0; + } + } + } } }; diff --git a/src/r_data/r_translate.h b/src/r_data/r_translate.h index f050f788e7..d71c64d44b 100644 --- a/src/r_data/r_translate.h +++ b/src/r_data/r_translate.h @@ -83,7 +83,7 @@ struct FRemapTable uint8_t Remap[256]; // For the software renderer PalEntry Palette[256]; // The ideal palette this maps to - FUniquePalette *Native; // The index into the list of unique palettes (this is to avoid frequent texture recreation with changing ACS translations) + FUniquePalette *Native = nullptr; // The index into the list of unique palettes (this is to avoid frequent texture recreation with changing ACS translations) //int crc32; int NumEntries; // # of elements in this table (usually 256) bool Inactive = false; // This table is inactive and should be treated as if it was passed as NULL