Skip to content

Commit

Permalink
Fixed loading screen not being disposed
Browse files Browse the repository at this point in the history
The Viewer object and its texture manager doesn't exist during the loading phase so cleanup must be done manually
  • Loading branch information
Sharpe49 committed Dec 11, 2021
1 parent 265b635 commit 564ae46
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Source/RunActivity/Viewer3D/Processes/GameStateRunActivity.cs
@@ -1,4 +1,4 @@
// COPYRIGHT 2009, 2010, 2011, 2012, 2013 by the Open Rails project.
// COPYRIGHT 2021 by the Open Rails project.
//
// This file is part of Open Rails.
//
Expand Down Expand Up @@ -36,7 +36,6 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;

namespace Orts.Viewer3D.Processes
Expand Down Expand Up @@ -79,6 +78,14 @@ public GameStateRunActivity(string[] args)
Arguments = args;
}

internal override void Dispose()
{
Loading.Dispose();
LoadingScreen.Dispose();
LoadingBar.Dispose();
base.Dispose();
}

internal override void Update(RenderFrame frame, double totalRealSeconds)
{
UpdateLoading();
Expand Down Expand Up @@ -1240,12 +1247,11 @@ long GetProcessBytesLoaded()
return 0;
}

class LoadingPrimitive : RenderPrimitive
class LoadingPrimitive : RenderPrimitive, IDisposable
{
public readonly LoadingMaterial Material;
readonly VertexBuffer VertexBuffer;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public LoadingPrimitive(Game game)
{
Material = GetMaterial(game);
Expand All @@ -1269,6 +1275,11 @@ virtual protected VertexPositionTexture[] GetVerticies(Game game)
new VertexPositionTexture(new Vector3(+dd - 0.5f, -dd + 0.5f, -3), new Vector2(1, 1)),
};
}

public void Dispose()
{
Material.Dispose();
}

public override void Draw(GraphicsDevice graphicsDevice)
{
Expand Down Expand Up @@ -1343,19 +1354,23 @@ protected override VertexPositionTexture[] GetVerticies(Game game)
}
}

class LoadingMaterial : Material
class LoadingMaterial : Material, IDisposable
{
public readonly LoadingShader Shader;
public readonly Texture2D Texture;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public LoadingMaterial(Game game)
: base(null, null)
{
Shader = new LoadingShader(game.RenderProcess.GraphicsDevice);
Texture = GetTexture(game);
}

public void Dispose()
{
Texture.Dispose();
}

virtual protected Texture2D GetTexture(Game game)
{
return SharedTextureManager.Get(game.RenderProcess.GraphicsDevice, Path.Combine(game.ContentPath, "Loading.png"));
Expand Down

0 comments on commit 564ae46

Please sign in to comment.