Skip to content

Commit 838cb63

Browse files
committed
Fixed loading screen not being disposed
The Viewer object and its texture manager doesn't exist during the loading phase so cleanup must be done manually
1 parent 5d0c86f commit 838cb63

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
1+
// COPYRIGHT 2021 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -36,7 +36,6 @@
3636
using System.Security.Cryptography;
3737
using System.Text;
3838
using System.Text.RegularExpressions;
39-
using System.Threading;
4039
using System.Windows.Forms;
4140

4241
namespace Orts.Viewer3D.Processes
@@ -79,6 +78,14 @@ public GameStateRunActivity(string[] args)
7978
Arguments = args;
8079
}
8180

81+
internal override void Dispose()
82+
{
83+
Loading.Dispose();
84+
LoadingScreen.Dispose();
85+
LoadingBar.Dispose();
86+
base.Dispose();
87+
}
88+
8289
internal override void Update(RenderFrame frame, double totalRealSeconds)
8390
{
8491
UpdateLoading();
@@ -1240,12 +1247,11 @@ long GetProcessBytesLoaded()
12401247
return 0;
12411248
}
12421249

1243-
class LoadingPrimitive : RenderPrimitive
1250+
class LoadingPrimitive : RenderPrimitive, IDisposable
12441251
{
12451252
public readonly LoadingMaterial Material;
12461253
readonly VertexBuffer VertexBuffer;
12471254

1248-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
12491255
public LoadingPrimitive(Game game)
12501256
{
12511257
Material = GetMaterial(game);
@@ -1269,6 +1275,11 @@ virtual protected VertexPositionTexture[] GetVerticies(Game game)
12691275
new VertexPositionTexture(new Vector3(+dd - 0.5f, -dd + 0.5f, -3), new Vector2(1, 1)),
12701276
};
12711277
}
1278+
1279+
public void Dispose()
1280+
{
1281+
Material.Dispose();
1282+
}
12721283

12731284
public override void Draw(GraphicsDevice graphicsDevice)
12741285
{
@@ -1343,19 +1354,23 @@ protected override VertexPositionTexture[] GetVerticies(Game game)
13431354
}
13441355
}
13451356

1346-
class LoadingMaterial : Material
1357+
class LoadingMaterial : Material, IDisposable
13471358
{
13481359
public readonly LoadingShader Shader;
13491360
public readonly Texture2D Texture;
13501361

1351-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
13521362
public LoadingMaterial(Game game)
13531363
: base(null, null)
13541364
{
13551365
Shader = new LoadingShader(game.RenderProcess.GraphicsDevice);
13561366
Texture = GetTexture(game);
13571367
}
13581368

1369+
public void Dispose()
1370+
{
1371+
Texture.Dispose();
1372+
}
1373+
13591374
virtual protected Texture2D GetTexture(Game game)
13601375
{
13611376
return SharedTextureManager.Get(game.RenderProcess.GraphicsDevice, Path.Combine(game.ContentPath, "Loading.png"));

0 commit comments

Comments
 (0)