Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

CreateSocialUserGroupFromList can return 0 users in the group #311

@NoelStephensNILC

Description

@NoelStephensNILC

I am still testing some things with this plugin, but it would appear that within the LoadProfileInfo method of the PlayerAuthentication.cs file the call to:
XboxLive.Instance.SocialManager.CreateSocialUserGroupFromList(this.xboxLiveUser, new List<string> { this.xboxLiveUser.XboxUserId });

Can sometimes return a users count of zero for a short period of time, but long enough period of time that the SocialManagerComponent.Instance.EventProcessed event notifications can fire off and notify the PlayerAuthentication's SocialManagerEventProcessed method before the XboxSocialUserGroup property (userGroup) has any entries in the Users list.

This series of events will cause the FinishLoadingProfileInfo Coroutine to throw an "invalid index" exception if it executes prior to there being any entries in the Users list contained within userGroup (XboxSocialUserGroup). This bug appears typically when running in any visual studio compiled release mode (i.e. Debug builds from within Unity Editor compiled as Release) version.

To verify this bug, you can add the following code within the LoadProfileInfo method:

                userGroup = XboxLive.Instance.SocialManager.CreateSocialUserGroupFromList(this.xboxLiveUser, new List<string> { this.xboxLiveUser.XboxUserId });
                if (userGroup.Count == 0)
                {
                    ExceptionManager.Instance.ThrowException(ExceptionSource.PlayerAuthentication, ExceptionType.CreateSocialUserGroupFailed, new Exception("CreateSocialUserGroupFromList Failed to return any users for the Group!"));                        
                }

A temporary work around (for anyone interested) would be something like:
(this is just pseudo-example code and you could also simply just check the userGroup.Users.Count prior to using the existing code that uses GetUsersFromXboxUserIds)

    XboxSocialUser currentsocialuser = null;
    private IEnumerator FinishLoadingProfileInfo()
    {
        while (currentsocialuser == null)
        {
            foreach (XboxSocialUser xboxsocuser in userGroup.Users)
            {
                currentsocialuser = xboxsocuser;
                if (currentsocialuser.XboxUserId == this.xboxLiveUser.XboxUserId)
                {
                    break;
                }
            }
            if(currentsocialuser != null)
            {
                break;
            }

            yield return new WaitForSeconds(2);
        }

        //var socialUser = userGroup.GetUsersFromXboxUserIds(new List<string> { this.xboxLiveUser.XboxUserId })[0];
        //var www  = new UnityWebRequest(currentsocialuser.DisplayPicRaw + "&w=128");
        var www = new WWW(currentsocialuser.DisplayPicRaw + "&w=128");
        yield return www;

        try
        {
            if (www.isDone && string.IsNullOrEmpty(www.error))
            {
                GamerPic = www.texture;
                UpdateGamerPic = true;
            }

        }
        catch (Exception ex)
        {
            ExceptionManager.Instance.ThrowException(
                        ExceptionSource.PlayerAuthentication,
                        ExceptionType.LoadGamerPicFailed,
                        ex);
        }
        
    }

Anyway, this one took me awhile to realize that it was a timing issue. This could be due to more recent changes in various libraries or the like and most likely at the time the original code was written did not present itself as it does today.

In case anyone is having issues with UserGroups, loading of profiles, and are using the original code from this library then you will most likely find this post helpful!

Cheers!
:)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions