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.
This commit is contained in:
Kawe Mazidjatari 2022-10-15 00:07:51 +02:00
parent 84dbc529d7
commit 9e9f29f4db
2 changed files with 23 additions and 11 deletions

View File

@ -81,7 +81,7 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* cache, MDLHandle_t handle, void* a3)
FindCachedMDL(cache, pStudioData, a3);
pMDLCache = *reinterpret_cast<void**>(pStudioData);
}
LABEL_6:
pStudioHdr = *reinterpret_cast<studiohdr_t**>(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<studiohdr_t**>(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<int>(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))

View File

@ -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<MDLHandle_t> g_vBadMDLHandles;
class CMDLCache