mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +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.CallbackHandle> CallbackHandles = new List<SteamNative.CallbackHandle>();
|
||||||
private List<SteamNative.CallResult> CallResults = new List<SteamNative.CallResult>();
|
private List<SteamNative.CallResult> CallResults = new List<SteamNative.CallResult>();
|
||||||
|
protected bool disposed = false;
|
||||||
|
|
||||||
|
|
||||||
protected BaseSteamworks( uint appId )
|
protected BaseSteamworks( uint appId )
|
||||||
@ -39,8 +40,15 @@ protected BaseSteamworks( uint appId )
|
|||||||
System.Environment.SetEnvironmentVariable("SteamGameId", AppId.ToString());
|
System.Environment.SetEnvironmentVariable("SteamGameId", AppId.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~BaseSteamworks()
|
||||||
|
{
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
|
if ( disposed ) return;
|
||||||
|
|
||||||
Callbacks.Clear();
|
Callbacks.Clear();
|
||||||
|
|
||||||
foreach ( var h in CallbackHandles )
|
foreach ( var h in CallbackHandles )
|
||||||
@ -81,6 +89,7 @@ public virtual void Dispose()
|
|||||||
|
|
||||||
System.Environment.SetEnvironmentVariable("SteamAppId", null );
|
System.Environment.SetEnvironmentVariable("SteamAppId", null );
|
||||||
System.Environment.SetEnvironmentVariable("SteamGameId", null );
|
System.Environment.SetEnvironmentVariable("SteamGameId", null );
|
||||||
|
disposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetupCommonInterfaces()
|
protected void SetupCommonInterfaces()
|
||||||
|
@ -135,6 +135,11 @@ public Client( uint appId ) : base( appId )
|
|||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Client()
|
||||||
|
{
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should be called at least once every frame
|
/// Should be called at least once every frame
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -163,6 +168,8 @@ public void RunCallbacks()
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
|
if ( disposed ) return;
|
||||||
|
|
||||||
if ( Voice != null )
|
if ( Voice != null )
|
||||||
{
|
{
|
||||||
Voice = null;
|
Voice = null;
|
||||||
|
@ -83,6 +83,11 @@ public Server( uint appId, ServerInit init) : base( appId )
|
|||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Server()
|
||||||
|
{
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should be called at least once every frame
|
/// Should be called at least once every frame
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -256,6 +261,8 @@ public void UpdatePlayer( ulong steamid, string name, int score )
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
|
if ( disposed ) return;
|
||||||
|
|
||||||
if ( Query != null )
|
if ( Query != null )
|
||||||
{
|
{
|
||||||
Query = null;
|
Query = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user