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 @@ public virtual void Dispose()
{
foreach ( var h in CallbackHandles )
{
h.UnregisterCallback();
h.Dispose();
}
CallbackHandles.Clear();

View File

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

View File

@ -40,19 +40,21 @@ public class VTable
public class CallbackHandle : IDisposable
{
internal BaseSteamworks steamworks;
internal SteamAPICall_t callHandle;
public GCHandle FuncA;
public GCHandle FuncB;
public GCHandle FuncC;
public IntPtr vTablePtr;
public GCHandle PinnedCallback;
internal SteamAPICall_t CallResultHandle;
internal bool CallResult;
internal GCHandle FuncA;
internal GCHandle FuncB;
internal GCHandle FuncC;
internal IntPtr vTablePtr;
internal GCHandle PinnedCallback;
public void Dispose()
{
if ( CallResult )
UnregisterCallResult();
else
UnregisterCallback();
if ( FuncA.IsAllocated )
FuncA.Free();
@ -72,50 +74,24 @@ public void Dispose()
}
}
internal void UnregisterCallback()
{
if ( PinnedCallback.IsAllocated )
private void UnregisterCallback()
{
if ( !PinnedCallback.IsAllocated )
return;
steamworks.native.api.SteamAPI_UnregisterCallback( PinnedCallback.AddrOfPinnedObject() );
}
Dispose();
}
internal void UnregisterCallResult()
private void UnregisterCallResult()
{
if ( PinnedCallback.IsAllocated )
{
steamworks.native.api.SteamAPI_UnregisterCallResult( PinnedCallback.AddrOfPinnedObject(), callHandle );
if ( CallResultHandle == 0 )
return;
if ( !PinnedCallback.IsAllocated )
return;
steamworks.native.api.SteamAPI_UnregisterCallResult( PinnedCallback.AddrOfPinnedObject(), CallResultHandle );
}
}
Dispose();
}
}
/*
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 @@ private void CallResult( SteamApiDefinition.StructDef c )
{
WriteLine( $"var handle = new CallbackHandle();" );
WriteLine( $"handle.steamworks = steamworks;" );
WriteLine( $"handle.callHandle = call;" );
WriteLine( $"handle.CallResultHandle = call;" );
WriteLine( $"handle.CallResult = true;" );
WriteLine( $"" );
WriteLine( "//" );
WriteLine( "// Create the functions we need for the vtable" );
WriteLine( "//" );
WriteLine( $"Callback.Result funcA = ( _, p ) => {{ CallbackFunction( FromPointer( p ), false ); handle.UnregisterCallResult(); }};" );
WriteLine( $"Callback.ResultWithInfo funcB = ( _, p, bIOFailure, hSteamAPICall ) => {{ CallbackFunction( FromPointer( p ), bIOFailure ); handle.UnregisterCallResult(); }};" );
WriteLine( $"Callback.Result funcA = ( _, p ) => {{ handle.Dispose(); CallbackFunction( FromPointer( p ), false ); }};" );
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();
WriteLine( "//" );