Skip to content

Commit 30dcac4

Browse files
VReaperVillwieckz
authored andcommitted
Fix memory leaks in material system portals
1 parent 7e00d8e commit 30dcac4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/engine/renderer/Material.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,8 @@ void MaterialSystem::GeneratePortalBoundingSpheres() {
16441644

16451645
// FIXME: This only requires distance, origin and radius can be moved to surfaceDescriptors SSBO,
16461646
// drawSurfID is not needed as it's the same as the index in portalSurfacesSSBO
1647-
PortalSurface* portalSurfs = new PortalSurface[totalPortals * sizeof( PortalSurface ) * MAX_VIEWFRAMES];
1647+
PortalSurface* portalSurfs =
1648+
( PortalSurface* ) ri.Hunk_AllocateTempMemory( totalPortals * MAX_VIEWFRAMES * sizeof( PortalSurface ) );
16481649

16491650
uint32_t index = 0;
16501651
for ( MaterialSurface& surface : portalSurfaces ) {
@@ -1665,6 +1666,8 @@ void MaterialSystem::GeneratePortalBoundingSpheres() {
16651666

16661667
portalSurfacesSSBO.BufferStorage( totalPortals * PORTAL_SURFACE_SIZE * MAX_VIEWS, 2, portalSurfs );
16671668
portalSurfacesSSBO.MapAll();
1669+
1670+
ri.Hunk_FreeTempMemory( portalSurfs );
16681671
}
16691672

16701673
void MaterialSystem::InitGLBuffers() {
@@ -1748,7 +1751,7 @@ bool MaterialSystem::AddPortalSurface( uint32_t viewID, PortalSurface* portalSur
17481751
frames[nextFrame].viewFrames[viewID].viewCount = 0;
17491752
portalStack[viewID].count = 0;
17501753

1751-
PortalSurface* tmpSurfs = new PortalSurface[totalPortals];
1754+
PortalSurface* tmpSurfs = ( PortalSurface* ) ri.Hunk_AllocateTempMemory( totalPortals * sizeof( PortalSurface ) );;
17521755
memcpy( tmpSurfs, portalSurfs + viewID * totalPortals, totalPortals * sizeof( PortalSurface ) );
17531756
std::sort( tmpSurfs, tmpSurfs + totalPortals,
17541757
[]( const PortalSurface& lhs, const PortalSurface& rhs ) {
@@ -1796,13 +1799,15 @@ bool MaterialSystem::AddPortalSurface( uint32_t viewID, PortalSurface* portalSur
17961799
viewCount++;
17971800

17981801
if ( count == MAX_VIEWS || viewCount == MAX_VIEWS ) {
1802+
ri.Hunk_FreeTempMemory( tmpSurfs );
17991803
return false;
18001804
}
18011805

18021806
for ( uint32_t j = 0; j < frames[currentFrame].viewFrames[viewID].viewCount; j++ ) {
18031807
uint32_t subView = frames[currentFrame].viewFrames[viewID].portalViews[j];
18041808
if ( subView != 0 && portalSurface->drawSurfID == frames[currentFrame].viewFrames[subView].portalSurfaceID ) {
18051809
if ( !AddPortalSurface( subView, portalSurfs ) ) {
1810+
ri.Hunk_FreeTempMemory( tmpSurfs );
18061811
return false;
18071812
}
18081813

@@ -1814,6 +1819,7 @@ bool MaterialSystem::AddPortalSurface( uint32_t viewID, PortalSurface* portalSur
18141819

18151820
memcpy( frames[nextFrame].viewFrames[viewID].portalViews, portalViews, MAX_VIEWS * sizeof( uint32_t ) );
18161821

1822+
ri.Hunk_FreeTempMemory( tmpSurfs );
18171823
return true;
18181824
}
18191825

0 commit comments

Comments
 (0)