From ae2b0aa3b55b3a42b6bf71e2aa7e9ce5996e81d8 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 19 Oct 2012 13:42:46 +0100 Subject: [PATCH] Fixed|PathDirectory: Failed assertion during abnormal shutdown --- doomsday/engine/portable/src/con_data.c | 48 ++++++++++++------- doomsday/engine/portable/src/fonts.c | 26 +++++++--- .../engine/portable/src/pathdirectory.cpp | 4 +- doomsday/engine/portable/src/wadfile.cpp | 2 + doomsday/engine/portable/src/zipfile.cpp | 2 + 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/doomsday/engine/portable/src/con_data.c b/doomsday/engine/portable/src/con_data.c index bc67ce7856..eef1390346 100644 --- a/doomsday/engine/portable/src/con_data.c +++ b/doomsday/engine/portable/src/con_data.c @@ -186,6 +186,8 @@ static void clearVariables(void) #else int flags = PCF_NO_BRANCH; #endif + if(!cvarDirectory) return; + PathDirectory_Iterate(cvarDirectory, flags, NULL, PATHDIRECTORY_NOHASH, clearVariable); PathDirectory_Clear(cvarDirectory); } @@ -387,7 +389,10 @@ static void updateKnownWords(void) countCVarParams.type = -1; countCVarParams.hidden = false; countCVarParams.ignoreHidden = true; - PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, countVariable, &countCVarParams); + if(cvarDirectory) + { + PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, countVariable, &countCVarParams); + } // Build the known words table. numKnownWords = numUniqueNamedCCmds + countCVarParams.count + numCAliases + GameCollection_Count(App_GameCollection()); @@ -1787,25 +1792,36 @@ D_CMD(ListVars) #if _DEBUG D_CMD(PrintVarStats) { - cvartype_t type; - countvariableparams_t p; + uint numCVars = 0, numCVarsHidden = 0; + Con_FPrintf(CPF_YELLOW, "Console Variable Statistics:\n"); - p.hidden = false; - p.ignoreHidden = false; - for(type = CVT_BYTE; type < CVARTYPE_COUNT; ++type) + if(cvarDirectory) { + cvartype_t type; + countvariableparams_t p; + p.hidden = false; + p.ignoreHidden = false; + for(type = CVT_BYTE; type < CVARTYPE_COUNT; ++type) + { + p.count = 0; + p.type = type; + PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, countVariable, &p); + Con_Printf("%12s: %u\n", Str_Text(CVar_TypeName(type)), p.count); + } p.count = 0; - p.type = type; + p.type = -1; + p.hidden = true; PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, countVariable, &p); - Con_Printf("%12s: %u\n", Str_Text(CVar_TypeName(type)), p.count); - } - p.count = 0; - p.type = -1; - p.hidden = true; - PathDirectory_Iterate2_Const(cvarDirectory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, countVariable, &p); - Con_Printf(" Total: %u\n Hidden: %u\n\n", PathDirectory_Size(cvarDirectory), p.count); - PathDirectory_DebugPrintHashDistribution(cvarDirectory); - PathDirectory_DebugPrint(cvarDirectory, CVARDIRECTORY_DELIMITER); + numCVars = PathDirectory_Size(cvarDirectory); + numCVarsHidden = p.count; + } + Con_Printf(" Total: %u\n Hidden: %u\n\n", numCVars, numCVarsHidden); + + if(cvarDirectory) + { + PathDirectory_DebugPrintHashDistribution(cvarDirectory); + PathDirectory_DebugPrint(cvarDirectory, CVARDIRECTORY_DELIMITER); + } return true; } #endif diff --git a/doomsday/engine/portable/src/fonts.c b/doomsday/engine/portable/src/fonts.c index 5423c1e6d4..408233e002 100644 --- a/doomsday/engine/portable/src/fonts.c +++ b/doomsday/engine/portable/src/fonts.c @@ -410,13 +410,16 @@ void Fonts_Shutdown(void) { fontnamespace_t* fn = &namespaces[i]; - PathDirectory_Iterate(fn->directory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, destroyRecord); - PathDirectory_Delete(fn->directory); - namespaces[i].directory = NULL; + if(fn->directory) + { + PathDirectory_Iterate(fn->directory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, destroyRecord); + PathDirectory_Delete(fn->directory); + fn->directory = 0; + } if(!fn->uniqueIdMap) continue; - free(fn->uniqueIdMap); - fn->uniqueIdMap = NULL; + free(fn->uniqueIdMap); fn->uniqueIdMap = 0; + fn->uniqueIdBase = 0; fn->uniqueIdMapSize = 0; fn->uniqueIdMapDirty = false; @@ -542,8 +545,13 @@ void Fonts_ClearNamespace(fontnamespaceid_t namespaceId) for(iter = from; iter <= to; ++iter) { fontnamespace_t* fn = &namespaces[iter - FONTNAMESPACE_FIRST]; - PathDirectory_Iterate(fn->directory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, destroyFontAndRecord); - PathDirectory_Clear(fn->directory); + + if(fn->directory) + { + PathDirectory_Iterate(fn->directory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, destroyFontAndRecord); + PathDirectory_Clear(fn->directory); + } + fn->uniqueIdMapDirty = true; } } @@ -1223,6 +1231,8 @@ static int iterateDirectory(fontnamespaceid_t namespaceId, for(iter = from; iter <= to; ++iter) { PathDirectory* directory = getDirectoryForNamespaceId(iter); + if(!directory) continue; + result = PathDirectory_Iterate2(directory, PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, callback, parameters); if(result) break; } @@ -1354,6 +1364,8 @@ static PathDirectoryNode** collectDirectoryNodes(fontnamespaceid_t namespaceId, for(iterId = fromId; iterId <= toId; ++iterId) { PathDirectory* fontDirectory = getDirectoryForNamespaceId(iterId); + if(!fontDirectory) continue; + PathDirectory_Iterate2(fontDirectory, PCF_NO_BRANCH|PCF_MATCH_FULL, NULL, PATHDIRECTORY_NOHASH, collectDirectoryNodeWorker, (void*)&p); } diff --git a/doomsday/engine/portable/src/pathdirectory.cpp b/doomsday/engine/portable/src/pathdirectory.cpp index 1ac34d295f..84ed2f1b2b 100644 --- a/doomsday/engine/portable/src/pathdirectory.cpp +++ b/doomsday/engine/portable/src/pathdirectory.cpp @@ -1097,8 +1097,6 @@ static int iteratePathsInHash(PathDirectory* pd, ushort hash, PathDirectoryNodeType type, int flags, PathDirectoryNode* parent_, int (*callback) (PathDirectoryNode* node, void* parameters), void* parameters) { - if(!pd) return 0; - int result = 0; SELF(pd); @@ -1191,6 +1189,7 @@ static int iteratePathsInHash_Const(PathDirectory const* pd, int PathDirectory_Iterate2(PathDirectory* pd, int flags, PathDirectoryNode* parent, ushort hash, pathdirectory_iteratecallback_t callback, void* parameters) { + DENG_ASSERT(pd); int result = 0; if(callback) { @@ -1214,6 +1213,7 @@ int PathDirectory_Iterate(PathDirectory* pd, int flags, PathDirectoryNode* paren int PathDirectory_Iterate2_Const(PathDirectory const* pd, int flags, PathDirectoryNode const* parent, ushort hash, pathdirectory_iterateconstcallback_t callback, void* parameters) { + DENG_ASSERT(pd); int result = 0; if(callback) { diff --git a/doomsday/engine/portable/src/wadfile.cpp b/doomsday/engine/portable/src/wadfile.cpp index bd77826e67..189ef1e48b 100644 --- a/doomsday/engine/portable/src/wadfile.cpp +++ b/doomsday/engine/portable/src/wadfile.cpp @@ -287,6 +287,8 @@ struct WadFile::Instance if(lumpNodeLut) return; lumpNodeLut = new LumpNodeLut(self->lumpCount()); + if(!lumpDirectory) return; + PathDirectory_Iterate2(reinterpret_cast(lumpDirectory), PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, buildLumpNodeLutWorker, (void*)this); } diff --git a/doomsday/engine/portable/src/zipfile.cpp b/doomsday/engine/portable/src/zipfile.cpp index 732c314d4a..d83562080f 100644 --- a/doomsday/engine/portable/src/zipfile.cpp +++ b/doomsday/engine/portable/src/zipfile.cpp @@ -422,6 +422,8 @@ struct ZipFile::Instance if(lumpNodeLut) return; lumpNodeLut = new LumpNodeLut(self->lumpCount()); + if(!lumpDirectory) return; + PathDirectory_Iterate2(reinterpret_cast(lumpDirectory), PCF_NO_BRANCH, NULL, PATHDIRECTORY_NOHASH, buildLumpNodeLutWorker, (void*)this); }