// 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);
+ // bones_was_here: +128 works around BUG https://github.com/DarkPlacesEngine/darkplaces/issues/119
+ // +64 was enough to start the map without triggering ASan, +96 was enough to also edit the light.
+ // See also: warning in Mod_ShadowMesh_AddMesh
+ r_shadow_compilingrtlight->static_meshchain_shadow_shadowmap = Mod_ShadowMesh_Begin(r_main_mempool, model->surfmesh.num_vertices, model->surfmesh.num_triangles + 128);
R_Shadow_PrepareShadowSides(model->surfmesh.num_triangles);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
{
for (i = 0;i < numtris;i++)
{
+ if ((mesh->numtriangles * 3 + 2) * sizeof(int) + 1 >= ((memheader_t *)((unsigned char *)mesh->element3i - sizeof(memheader_t)))->size)
+ {
+ // FIXME: we didn't allocate enough space for all the tris, see R_Mod_CompileShadowMap
+ Con_Print(CON_WARN "Mod_ShadowMesh_AddMesh: insufficient memory allocated!\n");
+ return;
+ }
mesh->element3i[mesh->numtriangles * 3 + 0] = Mod_ShadowMesh_AddVertex(mesh, vertex3f + 3 * element3i[i * 3 + 0]);
mesh->element3i[mesh->numtriangles * 3 + 1] = Mod_ShadowMesh_AddVertex(mesh, vertex3f + 3 * element3i[i * 3 + 1]);
mesh->element3i[mesh->numtriangles * 3 + 2] = Mod_ShadowMesh_AddVertex(mesh, vertex3f + 3 * element3i[i * 3 + 2]);