From b0371e18048ac12bc469a66679945ebf67ec287e Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 30 Aug 2013 22:38:57 -0500 Subject: [PATCH 1/2] Don't abort when merely checking if a non-map is a map - When P_OpenMapData() is called by P_CheckMapData(), we don't actually care if any required lumps are missing. This just means it isn't a valid map, so don't abort with I_Error(). --- src/compatibility.cpp | 2 +- src/g_level.cpp | 2 +- src/p_setup.cpp | 20 +++++++++++++++----- src/p_setup.h | 2 +- src/statistics.cpp | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/compatibility.cpp b/src/compatibility.cpp index 7bbff73224..dca0d34851 100644 --- a/src/compatibility.cpp +++ b/src/compatibility.cpp @@ -541,7 +541,7 @@ CCMD (mapchecksum) } for (int i = 1; i < argv.argc(); ++i) { - map = P_OpenMapData(argv[i]); + map = P_OpenMapData(argv[i], true); if (map == NULL) { Printf("Cannot load %s as a map\n", argv[i]); diff --git a/src/g_level.cpp b/src/g_level.cpp index 7e56d8843d..0b07ae2b56 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1923,7 +1923,7 @@ CCMD(listmaps) for(unsigned i = 0; i < wadlevelinfos.Size(); i++) { level_info_t *info = &wadlevelinfos[i]; - MapData *map = P_OpenMapData(info->mapname); + MapData *map = P_OpenMapData(info->mapname, true); if (map != NULL) { diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 784e6946fd..3693e9f7ea 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -250,7 +250,7 @@ static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname, // //=========================================================================== -MapData *P_OpenMapData(const char * mapname) +MapData *P_OpenMapData(const char * mapname, bool justcheck) { MapData * map = new MapData; FileReader * wadReader = NULL; @@ -331,13 +331,18 @@ MapData *P_OpenMapData(const char * mapname) const char * lumpname = Wads.GetLumpFullName(lump_name + i); try { - index = GetMapIndex(mapname, index, lumpname, true); + index = GetMapIndex(mapname, index, lumpname, !justcheck); } catch(...) { delete map; throw; } + if (index == -2) + { + delete map; + return NULL; + } if (index == ML_BEHAVIOR) map->HasBehavior = true; // The next lump is not part of this map anymore @@ -471,13 +476,18 @@ MapData *P_OpenMapData(const char * mapname) { try { - index = GetMapIndex(maplabel, index, lumpname, true); + index = GetMapIndex(maplabel, index, lumpname, !justcheck); } catch(...) { delete map; throw; } + if (index == -2) + { + delete map; + return NULL; + } if (index == ML_BEHAVIOR) map->HasBehavior = true; // The next lump is not part of this map anymore @@ -508,7 +518,7 @@ MapData *P_OpenMapData(const char * mapname) bool P_CheckMapData(const char *mapname) { - MapData *mapd = P_OpenMapData(mapname); + MapData *mapd = P_OpenMapData(mapname, true); if (mapd == NULL) return false; delete mapd; return true; @@ -3610,7 +3620,7 @@ void P_SetupLevel (char *lumpname, int position) P_FreeLevelData (); interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level. - MapData *map = P_OpenMapData(lumpname); + MapData *map = P_OpenMapData(lumpname, true); if (map == NULL) { I_Error("Unable to open map '%s'\n", lumpname); diff --git a/src/p_setup.h b/src/p_setup.h index 6e0a90a1d7..4a41a76f98 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -94,7 +94,7 @@ struct MapData void GetChecksum(BYTE cksum[16]); }; -MapData * P_OpenMapData(const char * mapname); +MapData * P_OpenMapData(const char * mapname, bool justcheck); bool P_CheckMapData(const char * mapname); diff --git a/src/statistics.cpp b/src/statistics.cpp index aa8d9afc16..81cd889835 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -463,7 +463,7 @@ void STAT_ChangeLevel(const char *newl) { // we reached the end of this episode int wad = 0; - MapData * map = P_OpenMapData(StartEpisode->mEpisodeMap); + MapData * map = P_OpenMapData(StartEpisode->mEpisodeMap, false); if (map != NULL) { wad = Wads.GetLumpFile(map->lumpnum); From 260ce62175e0a6f16bcc2fa6a61c2399db7633d6 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 30 Aug 2013 23:10:20 -0500 Subject: [PATCH 2/2] Don't abort for TEXTUREx lumps that define textures with no patches - A texture defined in TEXTUREx without any patches isn't necessarily an error, so accept. This also means they shouldn't be used for determining if a TEXTURE directory belongs to Strife instead of Doom. --- src/textures/multipatchtexture.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index 3083735a9e..fd2b59fb16 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -233,13 +233,13 @@ FMultiPatchTexture::FMultiPatchTexture (const void *texdef, FPatchLookup *patchl NumParts = SAFESHORT(mtexture.d->patchcount); } - if (NumParts <= 0) + if (NumParts < 0) { I_FatalError ("Bad texture directory"); } UseType = FTexture::TEX_Wall; - Parts = new TexPart[NumParts]; + Parts = NumParts > 0 ? new TexPart[NumParts] : NULL; Width = SAFESHORT(mtexture.d->width); Height = SAFESHORT(mtexture.d->height); strncpy (Name, (const char *)mtexture.d->name, 8); @@ -906,7 +906,7 @@ void FTextureManager::AddTexturesLump (const void *lumpdata, int lumpsize, int d // There is bizzarely a Doom editing tool that writes to the // first two elements of columndirectory, so I can't check those. - if (SAFESHORT(tex->patchcount) <= 0 || + if (SAFESHORT(tex->patchcount) < 0 || tex->columndirectory[2] != 0 || tex->columndirectory[3] != 0) {