Unload SDK pak files before Engine pak files

This is required, as we use assets within the engine pak files. Unloading the engine pak files first will result in a seg fault during shutdown.
This commit is contained in:
Kawe Mazidjatari 2022-10-07 22:22:32 +02:00
parent 72a60f6f39
commit 703caebe6b

View File

@ -213,8 +213,34 @@ void MOD_ProcessPakQueue()
}
if (!v14 || v13 == 9)
{
g_pakLoadApi->UnloadPak(*(_DWORD*)v10);
MOD_UnloadPakFile();
// SDK pak files must be unloaded before the engine pak files,
// as we reference assets within engine pak files.
const RPakLoadedInfo_t* pLoadedPakInfo = g_pRTech->GetPakLoadedInfo(*(RPakHandle_t*)v10);
if (pLoadedPakInfo)
{
const char* pszLoadedPakName = pLoadedPakInfo->m_pszFileName;
if (strcmp(pszLoadedPakName, "common_mp.rpak") == 0 ||
strcmp(pszLoadedPakName, "common_sp.rpak") == 0 ||
strcmp(pszLoadedPakName, "common_pve.rpak") == 0)
{
const RPakLoadedInfo_t* pLoadedSdkPak = g_pRTech->GetPakLoadedInfo("common_sdk.rpak");
if (pLoadedSdkPak) // Only unload if sdk pak file is loaded.
g_pakLoadApi->UnloadPak(pLoadedSdkPak->m_nHandle);
}
else if (strcmp(pszLoadedPakName, "ui_mp.rpak") == 0)
{
const RPakLoadedInfo_t* pLoadedSdkPak = g_pRTech->GetPakLoadedInfo("ui_sdk.rpak");
if (pLoadedSdkPak) // Only unload if sdk pak file is loaded.
g_pakLoadApi->UnloadPak(pLoadedSdkPak->m_nHandle);
}
}
g_pakLoadApi->UnloadPak(*(RPakHandle_t*)v10);
MOD_UnloadPakFile(); // Unload mod pak files.
}
if (v13 && (unsigned int)(v13 - 13) > 1)
return;
@ -388,7 +414,7 @@ void MOD_PreloadPakFile(const string& svLevelName)
//-----------------------------------------------------------------------------
void MOD_UnloadPakFile(void)
{
for (auto& it : g_vLoadedPakHandle)
for (const RPakHandle_t& it : g_vLoadedPakHandle)
{
if (it >= 0)
{