From 6e6368da300f7d024076e6272faa135280cf3bda Mon Sep 17 00:00:00 2001 From: s1lentq Date: Sun, 8 Dec 2024 00:36:04 +0700 Subject: [PATCH] CalcSurfaceExtents: more info in extents error message --- rehlds/engine/model.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rehlds/engine/model.cpp b/rehlds/engine/model.cpp index 162e4c5..e69d2c9 100644 --- a/rehlds/engine/model.cpp +++ b/rehlds/engine/model.cpp @@ -854,6 +854,7 @@ void CalcSurfaceExtents(msurface_t *s) int i, j, e; mvertex_t *v; mtexinfo_t *tex; + vec3_t middle{}; int bmins[2], bmaxs[2]; mins[0] = mins[1] = 999999; @@ -869,6 +870,8 @@ void CalcSurfaceExtents(msurface_t *s) else v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]]; + VectorAdd(middle, v->position, middle); + for (j = 0; j < 2; j++) { // FIXED: loss of floating point @@ -884,6 +887,8 @@ void CalcSurfaceExtents(msurface_t *s) } } + VectorScale(middle, 1.0f / s->numedges, middle); + for (i = 0; i < 2; i++) { bmins[i] = (int) floor(mins[i] / 16); @@ -891,8 +896,16 @@ void CalcSurfaceExtents(msurface_t *s) s->texturemins[i] = bmins[i] * 16; s->extents[i] = (bmaxs[i] - bmins[i]) * 16; + if (!(tex->flags & TEX_SPECIAL) && s->extents[i] > MAX_SURFACE_TEXTURE_SIZE) - Sys_Error("%s: Bad surface extents", __func__); + { + int surfID = s - loadmodel->surfaces; + Sys_Error("%s: Bad #%d surface extents %d/%d on %s at position (%d,%d,%d)", + __func__, surfID, s->extents[0], s->extents[1], + tex->texture->name, + (int)middle[0], (int)middle[1], (int)middle[2] + ); + } } }