From 20abf08dd0b559926494b75d8873347955da4c1d Mon Sep 17 00:00:00 2001 From: Grant Bagwell Date: Thu, 18 Feb 2021 18:45:52 +0100 Subject: [PATCH] More memory fixes --- .../neo/renderer/Model_md5.cpp | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/Model_md5.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/Model_md5.cpp index 3805694..010cac4 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/Model_md5.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/Model_md5.cpp @@ -235,13 +235,27 @@ void idMD5Mesh::ParseMesh( idLexer &parser, int numJoints, const idJointMat *joi // build the information that will be common to all animations of this mesh: // silhouette edge connectivity and normal / tangent generation information // - idDrawVert *verts = (idDrawVert *) _alloca16( texCoords.Num() * sizeof( idDrawVert ) ); + //GB Check there are not too many verts + // DG: windows only has a 1MB stack and it could happen that we try to allocate >1MB here + // (in lost mission mod, game/le_hell map), causing a stack overflow + // to prevent that, use heap allocation if it's >600KB + size_t allocaSize = texCoords.Num() * sizeof( idDrawVert ); + idDrawVert *verts; + if(allocaSize < 600000) + verts = (idDrawVert *) _alloca16( allocaSize ); + + else + verts = (idDrawVert *) Mem_Alloc16( allocaSize ); + for ( i = 0; i < texCoords.Num(); i++ ) { verts[i].Clear(); verts[i].st = texCoords[i]; } TransformVerts( verts, joints ); deformInfo = R_BuildDeformInfo( texCoords.Num(), verts, tris.Num(), tris.Ptr(), shader->UseUnsmoothedTangents() ); + + if(allocaSize >= 600000) + Mem_Free16( verts ); } /* @@ -352,12 +366,20 @@ idMD5Mesh::CalcBounds */ idBounds idMD5Mesh::CalcBounds( const idJointMat *entJoints ) { idBounds bounds; - idDrawVert *verts = (idDrawVert *) _alloca16( texCoords.Num() * sizeof( idDrawVert ) ); + + idDrawVert *verts; + size_t allocaSize = texCoords.Num() * sizeof( idDrawVert ); + if(allocaSize < 600000) + verts = (idDrawVert *) _alloca16( allocaSize ); + else + verts = (idDrawVert *) Mem_Alloc16( allocaSize ); TransformVerts( verts, entJoints ); SIMDProcessor->MinMax( bounds[0], bounds[1], verts, texCoords.Num() ); + if(allocaSize >= 600000) + Mem_Free16( verts ); return bounds; }