Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error related to unexpected Null #771

Open
Kaidoz opened this issue Jun 24, 2024 · 1 comment
Open

Error related to unexpected Null #771

Kaidoz opened this issue Jun 24, 2024 · 1 comment
Assignees

Comments

@Kaidoz
Copy link

Kaidoz commented Jun 24, 2024

Describe the bug
When the SteamInventory GetDefinitionsWithPricesAsync function is called, the result may return null.

To Reproduce
Steamworks.SteamInventory.GetDefinitionsWithPricesAsync()

Calling Code

Steamworks.SteamInventory.GetDefinitionsWithPricesAsync()

Expected behavior
The function must either return an empty list or have GetDefinitionsWithPricesOrDefaultAsync in its name.

Desktop (please complete the following information):

  • OS: Windows
  • Unity: 2022.1

Additional context
Violates the principles of clean code and can cause exception with null, when you don't expect it..

Fixed code

	public static async Task<InventoryDef[]> GetDefinitionsWithPricesAsync()
		{
			SteamInventoryRequestPricesResult_t? steamInventoryRequestPricesResult_t = await SteamInventory.Internal.RequestPrices();
			InventoryDef[] array = new InventoryDef[0];
			if (steamInventoryRequestPricesResult_t != null && steamInventoryRequestPricesResult_t.Value.Result == Result.OK)
			{
				SteamInventory.Currency = steamInventoryRequestPricesResult_t.GetValueOrDefault().CurrencyUTF8();
				uint numItemsWithPrices = SteamInventory.Internal.GetNumItemsWithPrices();
				if (numItemsWithPrices > 0U)
				{
					InventoryDefId[] array2 = new InventoryDefId[numItemsWithPrices];
					ulong[] array3 = new ulong[numItemsWithPrices];
					ulong[] array4 = new ulong[numItemsWithPrices];
					if (SteamInventory.Internal.GetItemsWithPrices(array2, array3, array4, numItemsWithPrices))
					{
						array = array2.Select((InventoryDefId x) => new InventoryDef(x)).ToArray<InventoryDef>();
					}
				}
			}
			return array;
		}
@Kaidoz
Copy link
Author

Kaidoz commented Jul 22, 2024

Hello, esteemed developer,

Every day, my Rust server triggers this type of error hundreds of times. This results in many Rust players being unable to play normally, severely affecting their gaming experience. They repeatedly try to reconnect, only to be disconnected again due to the error, until most players run out of patience and give up on Rust. Please pay attention to this issue and fix it promptly. Sincere thanks. ApplicationFrameHost_bxnnicFYpV ApplicationFrameHost_ltlrF38WzB @garrynewman

can you attach a log file with this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants