From 1fe426fb6554cf7ea9155c8ba61c5caa54ef9108 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 7 Jan 2024 02:05:14 +0100 Subject: [PATCH] DataCache: improve FindUncachedMDL error handling Just use a single branch. --- r5dev/datacache/mdlcache.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/r5dev/datacache/mdlcache.cpp b/r5dev/datacache/mdlcache.cpp index b7c5efe4..a787a4fc 100644 --- a/r5dev/datacache/mdlcache.cpp +++ b/r5dev/datacache/mdlcache.cpp @@ -182,34 +182,22 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* const cache, const MDLHandle_ FindCachedMDL(cache, pStudioData, a4); studiomodelcache_t* const modelCache = pStudioData->GetModelCache(); - if (modelCache) - { - if (modelCache == DC_INVALID_HANDLE) - { - studioHdr = GetErrorModel(); - if (!IsKnownBadModel(handle)) - { - if (!studioHdr) - Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model \"%s\" has bad studio data and \"%s\" couldn't be loaded.\n", modelName, ERROR_MODEL); - else - Error(eDLL_T::ENGINE, NO_ERROR, "Model \"%s\" has bad studio data; replacing with \"%s\".\n", modelName, ERROR_MODEL); - } - } - else - studioHdr = modelCache->GetStudioHdr(); - } - else + if (IS_VALID_DATACACHE_HANDLE(modelCache)) { studioHdr = GetErrorModel(); if (!IsKnownBadModel(handle)) { if (!studioHdr) - Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model \"%s\" has no studio data and \"%s\" couldn't be loaded.\n", modelName, ERROR_MODEL); + Error(eDLL_T::ENGINE, EXIT_FAILURE, "Model \"%s\" has invalid studio data and \"%s\" couldn't be loaded.\n", modelName, ERROR_MODEL); else - Error(eDLL_T::ENGINE, NO_ERROR, "Model \"%s\" has no studio data; replacing with \"%s\".\n", modelName, ERROR_MODEL); + Error(eDLL_T::ENGINE, NO_ERROR, "Model \"%s\" has invalid studio data; replacing with \"%s\".\n", modelName, ERROR_MODEL); } } + else + { + studioHdr = modelCache->GetStudioHdr(); + } } assert(studioHdr);