Skip to content

Commit 06a1171

Browse files
committed
Fix use-after-free in R_TryStitchingPatch
R_StitchPatches can replace a grid, invalidating the grid1 pointer.
1 parent d44893d commit 06a1171

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/engine/renderer/tr_bsp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,22 +2593,21 @@ might still appear at that side.
25932593
int R_TryStitchingPatch( int grid1num )
25942594
{
25952595
int j, numstitches;
2596-
srfGridMesh_t *grid1, *grid2;
25972596

25982597
numstitches = 0;
2599-
grid1 = ( srfGridMesh_t * ) s_worldData.surfaces[ grid1num ].data;
26002598

26012599
for ( j = 0; j < s_worldData.numSurfaces; j++ )
26022600
{
2603-
//
2604-
grid2 = ( srfGridMesh_t * ) s_worldData.surfaces[ j ].data;
2601+
srfGridMesh_t *grid2 = ( srfGridMesh_t * ) s_worldData.surfaces[ j ].data;
26052602

26062603
// if this surface is not a grid
26072604
if ( grid2->surfaceType != surfaceType_t::SF_GRID )
26082605
{
26092606
continue;
26102607
}
26112608

2609+
srfGridMesh_t *grid1 = ( srfGridMesh_t * ) s_worldData.surfaces[ grid1num ].data;
2610+
26122611
// grids in the same LOD group should have the exact same lod radius
26132612
if ( grid1->lodRadius != grid2->lodRadius )
26142613
{

0 commit comments

Comments
 (0)