Added finalizer, less chance of crashing with unity editor stop plays missing dispose

This commit is contained in:
Garry Newman 2018-02-19 14:36:07 +00:00
parent 6982d05042
commit bf2a074547
3 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,7 @@ public class BaseSteamworks : IDisposable
private List<SteamNative.CallbackHandle> CallbackHandles = new List<SteamNative.CallbackHandle>();
private List<SteamNative.CallResult> CallResults = new List<SteamNative.CallResult>();
protected bool disposed = false;
protected BaseSteamworks( uint appId )
@ -39,8 +40,15 @@ protected BaseSteamworks( uint appId )
System.Environment.SetEnvironmentVariable("SteamGameId", AppId.ToString());
}
~BaseSteamworks()
{
Dispose();
}
public virtual void Dispose()
{
if ( disposed ) return;
Callbacks.Clear();
foreach ( var h in CallbackHandles )
@ -81,6 +89,7 @@ public virtual void Dispose()
System.Environment.SetEnvironmentVariable("SteamAppId", null );
System.Environment.SetEnvironmentVariable("SteamGameId", null );
disposed = true;
}
protected void SetupCommonInterfaces()

View File

@ -135,6 +135,11 @@ public Client( uint appId ) : base( appId )
Update();
}
~Client()
{
Dispose();
}
/// <summary>
/// Should be called at least once every frame
/// </summary>
@ -163,6 +168,8 @@ public void RunCallbacks()
/// </summary>
public override void Dispose()
{
if ( disposed ) return;
if ( Voice != null )
{
Voice = null;

View File

@ -83,6 +83,11 @@ public Server( uint appId, ServerInit init) : base( appId )
Update();
}
~Server()
{
Dispose();
}
/// <summary>
/// Should be called at least once every frame
/// </summary>
@ -256,6 +261,8 @@ public void UpdatePlayer( ulong steamid, string name, int score )
/// </summary>
public override void Dispose()
{
if ( disposed ) return;
if ( Query != null )
{
Query = null;