This commit is contained in:
Garry Newman 2016-10-31 12:44:37 +00:00
parent bae105dbc9
commit c9443b75f2
5 changed files with 664 additions and 213 deletions

View File

@ -21,7 +21,7 @@ namespace Facepunch.Steamworks
{ {
foreach ( var h in CallbackHandles ) foreach ( var h in CallbackHandles )
{ {
h.UnregisterCallback(); h.Dispose();
} }
CallbackHandles.Clear(); CallbackHandles.Clear();

View File

@ -114,20 +114,17 @@ namespace Facepunch.Steamworks
private void OnItemCreated( SteamNative.CreateItemResult_t obj, bool Failed ) private void OnItemCreated( SteamNative.CreateItemResult_t obj, bool Failed )
{ {
if ( Failed )
throw new System.Exception( "CreateItemResult_t Failed" );
NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement; NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement;
CreateItem = null; CreateItem.Dispose();
if ( obj.Result == SteamNative.Result.OK ) if ( obj.Result == SteamNative.Result.OK && !Failed )
{ {
Id = obj.PublishedFileId; Id = obj.PublishedFileId;
PublishChanges(); PublishChanges();
return; return;
} }
Error = "Error creating new file: " + obj.Result.ToString(); Error = "Error creating new file: " + obj.Result.ToString() + "("+ obj.PublishedFileId+ ")";
Publishing = false; Publishing = false;
} }

View File

@ -40,19 +40,21 @@ namespace SteamNative
public class CallbackHandle : IDisposable public class CallbackHandle : IDisposable
{ {
internal BaseSteamworks steamworks; internal BaseSteamworks steamworks;
internal SteamAPICall_t CallResultHandle;
internal SteamAPICall_t callHandle; internal bool CallResult;
internal GCHandle FuncA;
public GCHandle FuncA; internal GCHandle FuncB;
public GCHandle FuncB; internal GCHandle FuncC;
public GCHandle FuncC; internal IntPtr vTablePtr;
internal GCHandle PinnedCallback;
public IntPtr vTablePtr;
public GCHandle PinnedCallback;
public void Dispose() public void Dispose()
{ {
if ( CallResult )
UnregisterCallResult();
else
UnregisterCallback();
if ( FuncA.IsAllocated ) if ( FuncA.IsAllocated )
FuncA.Free(); FuncA.Free();
@ -72,50 +74,24 @@ namespace SteamNative
} }
} }
internal void UnregisterCallback() private void UnregisterCallback()
{ {
if ( PinnedCallback.IsAllocated ) if ( !PinnedCallback.IsAllocated )
{ return;
steamworks.native.api.SteamAPI_UnregisterCallback( PinnedCallback.AddrOfPinnedObject() );
}
Dispose(); steamworks.native.api.SteamAPI_UnregisterCallback( PinnedCallback.AddrOfPinnedObject() );
} }
internal void UnregisterCallResult() private void UnregisterCallResult()
{ {
if ( PinnedCallback.IsAllocated ) if ( CallResultHandle == 0 )
{ return;
steamworks.native.api.SteamAPI_UnregisterCallResult( PinnedCallback.AddrOfPinnedObject(), callHandle );
}
Dispose(); if ( !PinnedCallback.IsAllocated )
return;
steamworks.native.api.SteamAPI_UnregisterCallResult( PinnedCallback.AddrOfPinnedObject(), CallResultHandle );
} }
} }
/*
public class CallResult<T> : IDisposable
{
public SteamAPICall_t Handle { get; private set; }
private Callback.Handle CallbackHandle;
internal CallResult( BaseSteamworks steamworks, SteamAPICall_t Handle, Callback.Handle CallbackHandle )
{
this.Handle = Handle;
this.CallbackHandle = CallbackHandle;
this.steamworks = steamworks;
}
public void Dispose()
{
if ( !steamworks.IsValid ) return;
if ( this.Handle == 0 ) return;
steamworks.native.api.SteamAPI_UnregisterCallResult( CallbackHandle.PinnedCallback.AddrOfPinnedObject(), Handle );
CallbackHandle.Dispose();
Handle = 0;
}
}
*/
} }

File diff suppressed because it is too large Load Diff

View File

@ -272,14 +272,24 @@ namespace Generator
{ {
WriteLine( $"var handle = new CallbackHandle();" ); WriteLine( $"var handle = new CallbackHandle();" );
WriteLine( $"handle.steamworks = steamworks;" ); WriteLine( $"handle.steamworks = steamworks;" );
WriteLine( $"handle.callHandle = call;" ); WriteLine( $"handle.CallResultHandle = call;" );
WriteLine( $"handle.CallResult = true;" );
WriteLine( $"" ); WriteLine( $"" );
WriteLine( "//" ); WriteLine( "//" );
WriteLine( "// Create the functions we need for the vtable" ); WriteLine( "// Create the functions we need for the vtable" );
WriteLine( "//" ); WriteLine( "//" );
WriteLine( $"Callback.Result funcA = ( _, p ) => {{ CallbackFunction( FromPointer( p ), false ); handle.UnregisterCallResult(); }};" ); WriteLine( $"Callback.Result funcA = ( _, p ) => {{ handle.Dispose(); CallbackFunction( FromPointer( p ), false ); }};" );
WriteLine( $"Callback.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => {{ CallbackFunction( FromPointer( p ), bIOFailure ); handle.UnregisterCallResult(); }};" ); StartBlock( $"Callback.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => " );
{
WriteLine( "if ( hSteamAPICall != call ) return;" );
WriteLine();
WriteLine( "handle.CallResultHandle = 0;" );
WriteLine( "handle.Dispose();" );
WriteLine();
WriteLine( "CallbackFunction( FromPointer( p ), bIOFailure );" );
}
EndBlock( ";" );
WriteLine( $"Callback.GetSize funcC = ( _ ) => {{ return Marshal.SizeOf( typeof( {c.Name} ) ); }};" ); WriteLine( $"Callback.GetSize funcC = ( _ ) => {{ return Marshal.SizeOf( typeof( {c.Name} ) ); }};" );
WriteLine(); WriteLine();
WriteLine( "//" ); WriteLine( "//" );