if (loadmodel->brush.numsubmodels)
loadmodel->brush.submodels = Mem_Alloc(loadmodel->mempool, loadmodel->brush.numsubmodels * sizeof(model_t *));
+ if (loadmodel->isworldmodel)
+ {
+ // clear out any stale submodels or worldmodels lying around
+ // if we did this clear before now, an error might abort loading and
+ // leave things in a bad state
+ Mod_RemoveStaleWorldModels(loadmodel);
+ }
+
// LordHavoc: to clear the fog around the original quake submodel code, I
// will explain:
// first of all, some background info on the submodels:
loadmodel->brush.num_leafs = 0;
Mod_Q3BSP_RecursiveFindNumLeafs(loadmodel->brush.data_nodes);
+ if (loadmodel->isworldmodel)
+ {
+ // clear out any stale submodels or worldmodels lying around
+ // if we did this clear before now, an error might abort loading and
+ // leave things in a bad state
+ Mod_RemoveStaleWorldModels(loadmodel);
+ }
+
mod = loadmodel;
for (i = 0;i < loadmodel->brush.numsubmodels;i++)
{
Con_DPrintf("loading model %s\n", mod->name);
// LordHavoc: unload the existing model in this slot (if there is one)
Mod_UnloadModel(mod);
- if (isworldmodel)
- {
- // clear out any stale submodels lying around, as well as the old world model itself
- int i;
- for (i = 0;i < MAX_MOD_KNOWN;i++)
- if (mod_known[i].isworldmodel)
- Mod_UnloadModel(mod_known + i);
- }
// load the model
mod->isworldmodel = isworldmodel;
Mod_FreeModel(mod);
}
+// only used during loading!
+void Mod_RemoveStaleWorldModels(model_t *skip)
+{
+ int i;
+ for (i = 0;i < MAX_MOD_KNOWN;i++)
+ if (mod_known[i].isworldmodel && skip != &mod_known[i])
+ Mod_UnloadModel(mod_known + i);
+}
+
void Mod_LoadModels(void)
{
int i;
void Mod_ClearUsed(void);
void Mod_PurgeUnused(void);
+void Mod_RemoveStaleWorldModels(model_t *skip); // only used during loading!
void Mod_LoadModels(void);
extern model_t *loadmodel;