Skip to content

Commit

Permalink
Fix a bug that textures of studiomodels can be unexpectedly freed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 19, 2024
1 parent 3f519ef commit 00adaff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 0 additions & 1 deletion Plugins/CaptionMod/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ void HUD_Init(void)
gPrivateFuncs.MessageMode_f = g_pMetaHookAPI->HookCmd("messagemode", MessageMode_f);
gPrivateFuncs.MessageMode2_f = g_pMetaHookAPI->HookCmd("messagemode2", MessageMode2_f);

//Fix SvClient Portal Rendering Confliction
if (g_bIsSvenCoop)
{
gPrivateFuncs.fmodex = GetModuleHandleA("fmodex.dll");
Expand Down
28 changes: 25 additions & 3 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2387,9 +2387,7 @@ void R_ForceCVars(qboolean mp)

void R_AddReferencedTextures(std::set<int> &textures)
{
int i;

for (i = 0; i < EngineGetNumKnownModel(); ++i)
for (int i = 0; i < EngineGetNumKnownModel(); ++i)
{
auto mod = EngineGetModelByIndex(i);

Expand Down Expand Up @@ -2448,6 +2446,29 @@ void R_UnloadNoreferenceTextures(const std::set<int>& textures)
}
}

void R_UnloadNoreferenceModels()
{
for (int i = 0; i < EngineGetNumKnownModel(); ++i)
{
auto mod = EngineGetModelByIndex(i);

if (mod && (mod->needload == NL_UNREFERENCED))
{
if (mod->type == mod_studio)
{
auto studiohdr = (studiohdr_t*)Cache_Check(&mod->cache);

if (studiohdr)
{
gEngfuncs.Con_DPrintf("R_UnloadNoreferenceModel: [mdl] [%s].\n", mod->name);

Cache_Free(&mod->cache);
}
}
}
}
}

void R_NewMap(void)
{
R_GenerateSceneUBO();
Expand Down Expand Up @@ -2476,6 +2497,7 @@ void R_NewMap(void)
std::set<int> textures;
R_AddReferencedTextures(textures);
R_UnloadNoreferenceTextures(textures);
R_UnloadNoreferenceModels();
}

(*r_framecount) = 1;
Expand Down

0 comments on commit 00adaff

Please sign in to comment.