From 2a9d4a98c5656b50a127be1da3a8a0535034628e Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 9 Feb 2014 18:51:06 +0100 Subject: [PATCH] check texlists at map load if by some freak accident the list gets corrupted, the textures are no longer accessible from the map editor this check makes sure, that nothing is missing --- source/src/worldio.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 539f9237..fce73a91 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -318,6 +318,25 @@ extern char *mlayout; extern int Mv, Ma, Hhits; extern float Mh; +void rebuildtexlists() // checks the texlists, if they still contain all possible textures +{ + short h[256]; + vector missing; + loopk(3) + { + missing.setsize(0); + uchar *p = hdr.texlists[k]; + loopi(256) h[i] = 0; + loopi(256) h[p[i]]++; + loopi(256) if(h[i] == 0) missing.add(i); + loopi(256) if(h[p[i]] > 1) + { + h[p[i]]--; + p[i] = missing.pop(); + } + } +} + bool load_world(char *mname) // still supports all map formats that have existed since the earliest cube betas! { const int sizeof_header = sizeof(header), sizeof_baseheader = sizeof_header - sizeof(int) * 16; @@ -364,6 +383,7 @@ bool load_world(char *mname) // still supports all map formats that have f->seek(tmp.headersize - sizeof_header - headerextrasize, SEEK_CUR); // (equivalent to SEEK_SET to tmp.headersize) } hdr = tmp; + rebuildtexlists(); loadingscreen("%s", hdr.maptitle); resetmap(); if(hdr.version>=4)