From 9e9f29f4dbb5c97e3a83a5b50166728a793f09da Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 15 Oct 2022 00:07:51 +0200 Subject: [PATCH] CMDLCache: fix bug and light cleanup * Fixed bug where we did not reset m_pErrorHDR to nullptr (m_pEmptyHDR was reset twice). * Light code cleanup. --- r5dev/datacache/mdlcache.cpp | 10 +++++++--- r5dev/datacache/mdlcache.h | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/r5dev/datacache/mdlcache.cpp b/r5dev/datacache/mdlcache.cpp index 079f1959..efbae0c7 100644 --- a/r5dev/datacache/mdlcache.cpp +++ b/r5dev/datacache/mdlcache.cpp @@ -81,7 +81,7 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* cache, MDLHandle_t handle, void* a3) FindCachedMDL(cache, pStudioData, a3); pMDLCache = *reinterpret_cast(pStudioData); } - LABEL_6: + pStudioHdr = *reinterpret_cast(pMDLCache); if (pStudioHdr) return pStudioHdr; @@ -90,7 +90,11 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* cache, MDLHandle_t handle, void* a3) } pMDLCache = pStudioData->m_pAnimData; if (pMDLCache) - goto LABEL_6; + { + pStudioHdr = *reinterpret_cast(pMDLCache); + if (pStudioHdr) + return pStudioHdr; + } } return FindUncachedMDL(cache, handle, pStudioData, a3); } @@ -156,7 +160,7 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* cache, MDLHandle_t handle, st size_t nFileNameLen = strlen(szModelName); - if (static_cast(nFileNameLen) < 5 || + if (nFileNameLen < 5 || (Q_stricmp(&szModelName[nFileNameLen - 5], ".rmdl") != 0) && (Q_stricmp(&szModelName[nFileNameLen - 5], ".rrig") != 0) && (Q_stricmp(&szModelName[nFileNameLen - 5], ".rpak") != 0)) diff --git a/r5dev/datacache/mdlcache.h b/r5dev/datacache/mdlcache.h index 991cbecf..0c8e31fd 100644 --- a/r5dev/datacache/mdlcache.h +++ b/r5dev/datacache/mdlcache.h @@ -14,19 +14,27 @@ struct RStaticProp_t uint8_t m_pUnknown[0x62]{}; }; -struct CMDLFallBack +struct RMDLFallBack_t { - studiohdr_t* m_pErrorHDR{}; - MDLHandle_t m_hErrorMDL{}; - studiohdr_t* m_pEmptyHDR{}; - MDLHandle_t m_hEmptyMDL{}; + studiohdr_t* m_pErrorHDR; + studiohdr_t* m_pEmptyHDR; + MDLHandle_t m_hErrorMDL; + MDLHandle_t m_hEmptyMDL; - // This has to be cleared if 'common.rpak' is getting unloaded! + RMDLFallBack_t(void) + : m_pErrorHDR(nullptr) + , m_pEmptyHDR(nullptr) + , m_hErrorMDL(NULL) + , m_hEmptyMDL(NULL) + { + } + + // This must be cleared if 'common.rpak' is getting unloaded! void Clear(void) { + m_pErrorHDR = nullptr; m_pEmptyHDR = nullptr; m_hErrorMDL = NULL; - m_pEmptyHDR = nullptr; m_hEmptyMDL = NULL; } }; @@ -52,7 +60,7 @@ struct studiodata_t int m_nGuidLock; // always -1, set to 1 and 0 in CMDLCache::FindUncachedMDL. }; -inline CMDLFallBack* g_pMDLFallback = new CMDLFallBack(); +inline RMDLFallBack_t* g_pMDLFallback = new RMDLFallBack_t(); inline vector g_vBadMDLHandles; class CMDLCache