From f39bef47cef43b2fb495a0ed2c99ae34dd56e367 Mon Sep 17 00:00:00 2001 From: havoc Date: Sat, 5 May 2018 08:54:40 +0000 Subject: [PATCH] Fix a bug in MD3 model loading that caused warnings from Mod_ValidateElements. Fix a bug in the output of Mod_ValidateElements which did not show the mismatching elements correctly. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12418 d7cf8633-e32d-0410-b094-e92efae38249 --- model_alias.c | 10 ++++++---- model_shared.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/model_alias.c b/model_alias.c index 3cd08bec..03ea5a38 100644 --- a/model_alias.c +++ b/model_alias.c @@ -1725,7 +1725,12 @@ void Mod_IDP3_Load(dp_model_t *mod, void *buffer, void *bufferend) meshtriangles += surface->num_triangles; for (j = 0;j < surface->num_triangles * 3;j++) - loadmodel->surfmesh.data_element3i[j + surface->num_firsttriangle * 3] = surface->num_firstvertex + LittleLong(((int *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_elements)))[j]); + { + int e = surface->num_firstvertex + LittleLong(((int *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_elements)))[j]); + loadmodel->surfmesh.data_element3i[j + surface->num_firsttriangle * 3] = e; + if (loadmodel->surfmesh.data_element3s) + loadmodel->surfmesh.data_element3s[j + surface->num_firsttriangle * 3] = e; + } for (j = 0;j < surface->num_vertices;j++) { loadmodel->surfmesh.data_texcoordtexture2f[(j + surface->num_firstvertex) * 2 + 0] = LittleFloat(((float *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_texcoords)))[j * 2 + 0]); @@ -1749,9 +1754,6 @@ void Mod_IDP3_Load(dp_model_t *mod, void *buffer, void *bufferend) Mod_ValidateElements(loadmodel->surfmesh.data_element3i + surface->num_firsttriangle * 3, loadmodel->surfmesh.data_element3s + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__); } - if (loadmodel->surfmesh.data_element3s) - for (i = 0;i < loadmodel->surfmesh.num_triangles*3;i++) - loadmodel->surfmesh.data_element3s[i] = loadmodel->surfmesh.data_element3i[i]; Mod_Alias_MorphMesh_CompileFrames(); loadmodel->surfmesh.isanimated = Mod_Alias_CalculateBoundingBox(); Mod_FreeSkinFiles(skinfiles); diff --git a/model_shared.c b/model_shared.c index 05c6fe57..1fc832be 100644 --- a/model_shared.c +++ b/model_shared.c @@ -746,7 +746,7 @@ qboolean Mod_ValidateElements(int *element3i, unsigned short *element3s, int num Con_Printf("Mod_ValidateElements(%i, %i, %i, %p, %p) called at %s:%d", numelements, first, last, element3i, element3s, filename, fileline); Con_Printf(", %i elements are invalid in element3i (example: element3i[%i] == %i)", invalidintcount, invalidintexample, element3i ? element3i[invalidintexample] : 0); Con_Printf(", %i elements are invalid in element3s (example: element3s[%i] == %i)", invalidshortcount, invalidshortexample, element3s ? element3s[invalidshortexample] : 0); - Con_Printf(", %i elements mismatch between element3i and element3s (example: element3s[%i] is %i and element3i[i] is %i)", invalidmismatchcount, invalidmismatchexample, element3i ? element3i[invalidmismatchexample] : 0, invalidmismatchexample, element3s ? element3s[invalidmismatchexample] : 0); + Con_Printf(", %i elements mismatch between element3i and element3s (example: element3s[%i] is %i and element3i[%i] is %i)", invalidmismatchcount, invalidmismatchexample, element3s ? element3s[invalidmismatchexample] : 0, invalidmismatchexample, element3i ? element3i[invalidmismatchexample] : 0); Con_Print(". Please debug the engine code - these elements have been modified to not crash, but nothing more.\n"); // edit the elements to make them safer, as the driver will crash otherwise -- 2.39.2