From: havoc Date: Tue, 30 Aug 2005 08:53:01 +0000 (+0000) Subject: modified Mod_ValidateElements to fix broken elements rather than crashing later X-Git-Tag: xonotic-v0.1.0preview~4602 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e3272446d9f13cc12b1822a99b4e7cf512454db9;p=xonotic%2Fdarkplaces.git modified Mod_ValidateElements to fix broken elements rather than crashing later git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5672 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/model_shared.c b/model_shared.c index ab7de28c..e99affc5 100644 --- a/model_shared.c +++ b/model_shared.c @@ -480,12 +480,21 @@ void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtria } #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++) + { 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! diff --git a/model_shared.h b/model_shared.h index 6cfc5104..cf771ed1 100644 --- a/model_shared.h +++ b/model_shared.h @@ -559,7 +559,7 @@ extern char loadname[32]; // for hunk tags int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices); void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles); -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); void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f, qboolean areaweighting); void Mod_BuildTextureVectorsAndNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals, qboolean areaweighting);