mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Added finalizer, less chance of crashing with unity editor stop plays missing dispose
This commit is contained in:
parent
6982d05042
commit
bf2a074547
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user