]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
rearranged stale worldmodel removal a bit so that trying to load a level that doesn...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 Mar 2005 14:49:39 +0000 (14:49 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 Mar 2005 14:49:39 +0000 (14:49 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5123 d7cf8633-e32d-0410-b094-e92efae38249

model_brush.c
model_shared.c
model_shared.h

index 087430c6967c7056d5732435acb1ddac11668755..46644226448066bcf06162022c2a107540f856e1 100644 (file)
@@ -2982,6 +2982,14 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
        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:
@@ -5458,6 +5466,14 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
        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++)
        {
index 34859f8c8ad611ab30ef73a06c0fcca25c0c6171..50fb26998462c43ab0094a3e8f915435b200a232 100644 (file)
@@ -280,14 +280,6 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk,
        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;
@@ -384,6 +376,15 @@ void Mod_PurgeUnused(void)
                                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;
index 136cf854ad5c34edd2c6761ecf3284bcd19cd7d0..3123203f557c6c90919097af37f33aaf1b79b7fb 100644 (file)
@@ -456,6 +456,7 @@ void Mod_UnloadModel (model_t *mod);
 
 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;