From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Tue, 1 May 2018 06:48:05 +0000 (+0000)
Subject: Fix a crash on Doombringer duel5.bsp where one of the lights has more than 32768... 
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=46964b3848eb7471d2f0e2284ae389b4b53337c1;p=xonotic%2Fdarkplaces.git

Fix a crash on Doombringer duel5.bsp where one of the lights has more than 32768 triangles - this was using more than one shadowmesh and the sidetotals code was written incorrectly to assume there is a single shadowmesh per light - so now shadowmeshes are preallocated large enough for the entire model, to ensure there is only one.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12412 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/gl_rsurf.c b/gl_rsurf.c
index cd4c08bb..3051aa0b 100644
--- a/gl_rsurf.c
+++ b/gl_rsurf.c
@@ -1383,7 +1383,12 @@ void R_Q1BSP_CompileShadowMap(entity_render_t *ent, vec3_t relativelightorigin,
 	int i;
 	if (!model->brush.shadowmesh)
 		return;
-	r_shadow_compilingrtlight->static_meshchain_shadow_shadowmap = Mod_ShadowMesh_Begin(r_main_mempool, 32768, 32768, NULL, NULL, NULL, false, false, true);
+	// FIXME: the sidetotals code incorrectly assumes that static_meshchain is
+	// a single mesh - to prevent that from crashing (sideoffsets, sidetotals
+	// exceeding the number of triangles in a single mesh) we have to make sure
+	// that we make only a single mesh - so over-estimate the size of the mesh
+	// to match the model.
+	r_shadow_compilingrtlight->static_meshchain_shadow_shadowmap = Mod_ShadowMesh_Begin(r_main_mempool, model->surfmesh.num_vertices, model->surfmesh.num_triangles, NULL, NULL, NULL, false, false, true);
 	R_Shadow_PrepareShadowSides(model->brush.shadowmesh->numtriangles);
 	for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
 	{