Don't release inventoryg result in InventoryUpdated callback

This commit is contained in:
Garry Newman 2019-05-13 15:51:55 +01:00
parent 69ec868227
commit 7a30b76a26
3 changed files with 33 additions and 3 deletions

View File

@ -54,10 +54,13 @@ public async Task GetAllItems()
var result = await SteamInventory.GetAllItemsAsync();
Assert.IsTrue( result.HasValue );
Assert.IsTrue( result.Value.ItemCount > 0 );
using ( result )
{
var items = result?.GetItems( true );
var items = result.Value.GetItems( true );
Assert.IsNotNull( items );
foreach ( var item in items )
{
@ -71,6 +74,33 @@ public async Task GetAllItems()
}
}
[TestMethod]
public async Task GetAllItemsMultipleTimes()
{
await SteamInventory.WaitForDefinitions();
var fresult = await SteamInventory.GetAllItemsAsync();
Assert.IsTrue( fresult.HasValue );
Assert.IsTrue( fresult.Value.ItemCount > 0 );
await Task.Delay( 1000 );
var result = await SteamInventory.GetAllItemsAsync();
Assert.IsTrue( result.HasValue );
Assert.IsTrue( result.Value.GetItems().Length == fresult.Value.ItemCount );
await Task.Delay( 1000 );
result = await SteamInventory.GetAllItemsAsync();
Assert.IsTrue( result.HasValue );
Assert.IsTrue( result.Value.ItemCount == fresult.Value.ItemCount );
}
[TestMethod]
public async Task Items()
{

View File

@ -46,8 +46,6 @@ private static void InventoryUpdated( SteamInventoryFullUpdate_t x )
Items = r.GetItems( false );
OnInventoryUpdated?.Invoke( r );
r.Dispose();
}
public static event Action<InventoryResult> OnInventoryUpdated;

View File

@ -58,6 +58,8 @@ public InventoryItem[] GetItems( bool includeProperties = false )
public void Dispose()
{
if ( _id.Value == -1 ) return;
SteamInventory.Internal.DestroyResult( _id );
}