Skip to content

Commit f6deb33

Browse files
committed
Dispose unmarked shapes' buffers
1 parent 0929cde commit f6deb33

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public void Mark(SharedShape shape)
101101
public void Sweep()
102102
{
103103
foreach (var path in ShapeMarks.Where(kvp => !kvp.Value).Select(kvp => kvp.Key))
104+
{
105+
Shapes[path].Dispose();
104106
Shapes.Remove(path);
107+
}
105108
}
106109

107110
[CallOnThread("Updater")]
@@ -1343,7 +1346,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
13431346
}
13441347
}
13451348

1346-
public class ShapePrimitive : RenderPrimitive
1349+
public class ShapePrimitive : RenderPrimitive, IDisposable
13471350
{
13481351
public Material Material { get; protected set; }
13491352
public int[] Hierarchy { get; protected set; } // the hierarchy from the sub_object
@@ -1394,6 +1397,13 @@ public virtual void Mark()
13941397
{
13951398
Material.Mark();
13961399
}
1400+
1401+
public void Dispose()
1402+
{
1403+
VertexBuffer.Dispose();
1404+
IndexBuffer.Dispose();
1405+
PrimitiveCount = 0;
1406+
}
13971407
}
13981408

13991409
/// <summary>
@@ -1535,7 +1545,7 @@ public virtual void Mark()
15351545
}
15361546
#endif
15371547

1538-
public class SharedShape
1548+
public class SharedShape : IDisposable
15391549
{
15401550
static List<string> ShapeWarnings = new List<string>();
15411551

@@ -1668,7 +1678,7 @@ void LoadContent()
16681678
}
16691679
}
16701680

1671-
public class LodControl
1681+
public class LodControl : IDisposable
16721682
{
16731683
public DistanceLevel[] DistanceLevels;
16741684

@@ -1687,11 +1697,21 @@ public LodControl(lod_control MSTSlod_control, Helpers.TextureFlags textureFlags
16871697
internal void Mark()
16881698
{
16891699
foreach (var dl in DistanceLevels)
1700+
{
16901701
dl.Mark();
1702+
}
1703+
}
1704+
1705+
public void Dispose()
1706+
{
1707+
foreach (var dl in DistanceLevels)
1708+
{
1709+
dl.Dispose();
1710+
}
16911711
}
16921712
}
16931713

1694-
public class DistanceLevel
1714+
public class DistanceLevel : IDisposable
16951715
{
16961716
public float ViewingDistance;
16971717
public float ViewSphereRadius;
@@ -1726,11 +1746,21 @@ public DistanceLevel(distance_level MSTSdistance_level, Helpers.TextureFlags tex
17261746
internal void Mark()
17271747
{
17281748
foreach (var so in SubObjects)
1749+
{
17291750
so.Mark();
1751+
}
1752+
}
1753+
1754+
public void Dispose()
1755+
{
1756+
foreach (var so in SubObjects)
1757+
{
1758+
so.Dispose();
1759+
}
17301760
}
17311761
}
17321762

1733-
public class SubObject
1763+
public class SubObject : IDisposable
17341764
{
17351765
static readonly SceneryMaterialOptions[] UVTextureAddressModeMap = new[] {
17361766
SceneryMaterialOptions.TextureAddressModeWrap,
@@ -1951,7 +1981,17 @@ public SubObject(sub_object sub_object, ref int totalPrimitiveIndex, int[] hiera
19511981
internal void Mark()
19521982
{
19531983
foreach (var prim in ShapePrimitives)
1984+
{
19541985
prim.Mark();
1986+
}
1987+
}
1988+
1989+
public void Dispose()
1990+
{
1991+
foreach (var prim in ShapePrimitives)
1992+
{
1993+
prim.Dispose();
1994+
}
19551995
}
19561996
}
19571997

@@ -2180,7 +2220,17 @@ internal void Mark()
21802220
{
21812221
Viewer.ShapeManager.Mark(this);
21822222
foreach (var lod in LodControls)
2223+
{
21832224
lod.Mark();
2225+
}
2226+
}
2227+
2228+
public void Dispose()
2229+
{
2230+
foreach (var lod in LodControls)
2231+
{
2232+
lod.Dispose();
2233+
}
21842234
}
21852235
}
21862236

0 commit comments

Comments
 (0)