]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
migrated a lot of error handling out of R_Shadow_RenderLighting and into the loading...
[xonotic/darkplaces.git] / model_shared.c
index 4e77c52b2714316d3146e33f0d709ad157e398b3..29dcad643d44daa7c74483917dbcbd9f9909a5a6 100644 (file)
@@ -189,18 +189,22 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea
 
        if (buf)
        {
 
        if (buf)
        {
+               char *bufend = (char *)buf + fs_filesize;
                num = LittleLong(*((int *)buf));
                // call the apropriate loader
                loadmodel = mod;
                num = LittleLong(*((int *)buf));
                // call the apropriate loader
                loadmodel = mod;
-                    if (!memcmp(buf, "IDPO", 4)) Mod_IDP0_Load(mod, buf);
-               else if (!memcmp(buf, "IDP2", 4)) Mod_IDP2_Load(mod, buf);
-               else if (!memcmp(buf, "IDP3", 4)) Mod_IDP3_Load(mod, buf);
-               else if (!memcmp(buf, "IDSP", 4)) Mod_IDSP_Load(mod, buf);
-               else if (!memcmp(buf, "IDS2", 4)) Mod_IDS2_Load(mod, buf);
-               else if (!memcmp(buf, "IBSP", 4)) Mod_IBSP_Load(mod, buf);
-               else if (!memcmp(buf, "ZYMOTICMODEL", 12)) Mod_ZYMOTICMODEL_Load(mod, buf);
-               else if (strlen(mod->name) >= 4 && !strcmp(mod->name - 4, ".map")) Mod_MAP_Load(mod, buf);
-               else if (num == BSPVERSION || num == 30) Mod_Q1BSP_Load(mod, buf);
+                    if (!memcmp(buf, "IDPO", 4)) Mod_IDP0_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "IDP2", 4)) Mod_IDP2_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "IDP3", 4)) Mod_IDP3_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "IDSP", 4)) Mod_IDSP_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "IDS2", 4)) Mod_IDS2_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "IBSP", 4)) Mod_IBSP_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "ZYMOTICMODEL", 12)) Mod_ZYMOTICMODEL_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "DARKPLACESMODEL", 16)) Mod_DARKPLACESMODEL_Load(mod, buf, bufend);
+               else if (!strcmp(buf, "ACTRHEAD")) Mod_PSKMODEL_Load(mod, buf, bufend);
+               else if (strlen(mod->name) >= 4 && !strcmp(mod->name - 4, ".map")) Mod_MAP_Load(mod, buf, bufend);
+               else if (!memcmp(buf, "MCBSP", 5)) Mod_Q1BSP_Load(mod, buf, bufend);
+               else if (num == BSPVERSION || num == 30) Mod_Q1BSP_Load(mod, buf, bufend);
                else Con_Printf("Mod_LoadModel: model \"%s\" is of unknown/unsupported type\n", mod->name);
                Mem_Free(buf);
        }
                else Con_Printf("Mod_LoadModel: model \"%s\" is of unknown/unsupported type\n", mod->name);
                Mem_Free(buf);
        }
@@ -477,12 +481,21 @@ void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtria
 }
 #endif
 
 }
 #endif
 
-void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline)
+void Mod_ValidateElements(int *elements, int numtriangles, int numverts, const char *filename, int fileline)
 {
 {
-       int i;
+       int i, warned = false;
        for (i = 0;i < numtriangles * 3;i++)
        for (i = 0;i < numtriangles * 3;i++)
+       {
                if ((unsigned int)elements[i] >= (unsigned int)numverts)
                if ((unsigned int)elements[i] >= (unsigned int)numverts)
-                       Con_Printf("Mod_ValidateElements: out of bounds element detected at %s:%d\n", filename, fileline);
+               {
+                       if (!warned)
+                       {
+                               warned = true;
+                               Con_Printf("Mod_ValidateElements: out of bounds elements detected at %s:%d\n", filename, fileline);
+                       }
+                       elements[i] = 0;
+               }
+       }
 }
 
 // warning: this is an expensive function!
 }
 
 // warning: this is an expensive function!
@@ -926,6 +939,10 @@ int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags,
                if (s.shirtpixels != NULL)
                        skinframe->shirt = R_LoadTexture2D (loadmodel->texturepool, va("%s_shirt", basename), s.shirtpixels_width, s.shirtpixels_height, s.shirtpixels, TEXTYPE_RGBA, textureflags, NULL);
        }
                if (s.shirtpixels != NULL)
                        skinframe->shirt = R_LoadTexture2D (loadmodel->texturepool, va("%s_shirt", basename), s.shirtpixels_width, s.shirtpixels_height, s.shirtpixels, TEXTYPE_RGBA, textureflags, NULL);
        }
+       if (!skinframe->base)
+               skinframe->base = r_texture_notexture;
+       if (!skinframe->nmap)
+               skinframe->nmap = r_texture_blanknormalmap;
        image_freeskin(&s);
        return true;
 }
        image_freeskin(&s);
        return true;
 }
@@ -970,6 +987,8 @@ int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textu
                                skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename), palette_nocolormap, textureflags); // no pants or shirt
                }
        }
                                skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename), palette_nocolormap, textureflags); // no pants or shirt
                }
        }
+       if (!skinframe->nmap)
+               skinframe->nmap = r_texture_blanknormalmap;
        return true;
 }
 
        return true;
 }