From 13280cd57c0db446d6a506d23aa151e191258628 Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Thu, 1 Nov 2018 08:35:49 -0400 Subject: [PATCH] Fix GetAvatar sometimes failing instead of waiting for the avatar to load --- Facepunch.Steamworks/Client/Friends.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Facepunch.Steamworks/Client/Friends.cs b/Facepunch.Steamworks/Client/Friends.cs index 0a95d0a..f49a950 100644 --- a/Facepunch.Steamworks/Client/Friends.cs +++ b/Facepunch.Steamworks/Client/Friends.cs @@ -271,9 +271,19 @@ public void GetAvatar( AvatarSize size, ulong steamid, Action callback ) // Lets request it from Steam if (!client.native.friends.RequestUserInformation(steamid, false)) { - // Steam told us to get fucked - callback(null); - return; + // from docs: false means that we already have all the details about that user, and functions that require this information can be used immediately + // but that's probably not true because we just checked the cache + + // check again in case it was just a race + image = GetCachedAvatar(size, steamid); + if ( image != null ) + { + callback(image); + return; + } + + // maybe Steam returns false if it was already requested? just add another callback and hope it comes + // if not it'll time out anyway } PersonaCallbacks.Add( new PersonaCallback @@ -326,7 +336,10 @@ internal void Cycle() { if ( cb.Callback != null ) { - cb.Callback( null ); + // final attempt, will be null unless the callback was missed somehow + var image = GetCachedAvatar( cb.Size, cb.SteamId ); + + cb.Callback( image ); } PersonaCallbacks.Remove( cb );