question

Matthew Tighe avatar image
Matthew Tighe asked

PlayFab Party in Unity - Network Teardown on Error

Hello,

We are using PlayFab Party in Unity and having a major problem when any kind of network issue or re-connection occurs.

Whenever we then try to create a Network with CreateAndJoinNetwork this will either just never callback, or OnError will fire with one of the following error codes:

4098 = the operation was called with an invalid handle
4330 = an unknown error code was returned by the PlayFab service

We always try to leave any network before we create another, I cannot see any other methods to call to tear anything down or reset it?

Any help greatly appreciated.

unity3d
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

May I know your title id and the version of the Party SDK you're using? And, do you mind sharing the code snippet you're using that reproduces this issue?

0 Likes 0 ·
Matthew Tighe avatar image
Matthew Tighe answered
Hi Citrus,

The TitleId is: 58956 and we are using playfab-party.1.5.0.1-main.0-10.27.2020-preview for Unity.

Our game is targeting Windows Gamecore using the GDK. We ran the GDK install script in the PlayFabParty plugin for Unity as described. Perhaps there is something there we could verify?

In terms of reproduction, this issue happens either in real builds or in the Editor.

On Start of our scene, we register the PlayFabParty listeners:

    public void Start()
    {
        if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
        {
            PlayFabSettings.staticSettings.TitleId = "58956";
        }
        PlayFabMultiplayerManager.Get().OnNetworkJoined += OnNetworkJoined;
        PlayFabMultiplayerManager.Get().OnNetworkLeft += OnNetworkLeft;
        PlayFabMultiplayerManager.Get().OnError += OnPlayFabError;
    }

Upon user pressing a "Start Matchmaking" button, the game logs in:

if(lastLoginResult == null || !PlayFabClientAPI.IsClientLoggedIn()){  var request = new LoginWithCustomIDRequest {    CustomId = PlayerId, CreateAccount = true  };
  PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);
}

Note that in builds we are using XboxLive Authentication, in the Editor we are using a CustomId Authentication just for testing. But the flow is identical.

We cache the lastLoginResult and also try to validate the client is logged in. But removing that makes no difference to the problems encountered.

In the OnLoginSuccess event, we simply create a Party Network:

PlayFabMultiplayerManager.Get().CreateAndJoinNetwork();

We then wait for the OnNetworkJoined event and continue from there.

When the game is finished or if an error occurs or the game is cancelled we do the following:

PlayFabMultiplayerManager.Get().LeaveNetwork();PlayFabMultiplayerAPI.CancelMatchmakingTicket(
  new CancelMatchmakingTicketRequest
  {
    QueueName = MatchmakingQueue,
    TicketId = matchmakingTicketId,
  },
  this.OnMatchmakingTicketCancelled,
  this.OnMatchmakingError);

In normal situations this works fine, the user can play many games they can cancel or let the game complete. Disconnections also work (we use our cancel logic above in response to OnRemotePlayerLeft).

However, if there is any kind of network issue, then we we restart the whole process... the call to CreateAndJoinNetwork will never call either the success or failure callback. And most times we get OnError event with the error codes mentioned in the first post.

It can also be reproduced by starting the game with no network connection. If you then plug cable in, the problem will occur on the very first attempt.

It seems to be related to login state, or something not being appropriately reset. But we can't find any documenation or other methods we should call in the lifecycle. So any advice greatly appreciated.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Hi Matthew,

I was able to reproduce error 4098, please allow me to investigate further before giving you a proper advice.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Citrus Yan commented ·

Regard error 4330, I was not able to reproduce it, are you still seeing this?

0 Likes 0 ·
Matthew Tighe avatar image
Matthew Tighe answered

Hi Citrus,

We were still seeing 4330 (and actually several other errors), it appears to be due to some errors marshalling objects between the native DLL and the CS layer.

There are also several places in the state machine where it will just hang in certain circumstances particularly around login after network connection if that app was booted without.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Here is what I tried: change PlayFabMultiplayerManager's State to Initialized when network's down, by doing this, error 4098 won't occur, here is the code snippet I used, you can have a try:

    float elapsed = 0f;
    bool stateSet = false;
    void Update()
    {
        elapsed += Time.deltaTime;
        if (elapsed >= 3f) //check network every 3 secs
        {
            elapsed = elapsed % 3f;
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Debug.Log("Error. Check internet connection!");


                if (PlayFabClientAPI.IsClientLoggedIn() && stateSet == false)
                {
                    stateSet = true;
                    PlayFabMultiplayerManager.Get()._SetPlayFabMultiplayerManagerInternalState(PlayFabMultiplayerManager._InternalPlayFabMultiplayerManagerState.Initialized);
                }
            }
        }
    }

1 Like 1 ·
Matthew Tighe avatar image
Matthew Tighe answered

Thanks Citrus,

We arrived at something similar, resetting the state before each session we created. We seem to have addressed most issues - though there were many places we had to tweak the PlayFabMultiplayerManager state machine for different edge cases.

The remaining issue is that we often get strange errors marshalling objects between the native and cs layer. It seems to be related to the region list.

In the state PARTY_CREATE_NEW_NETWORK_COMPLETED_STATE_CHANGE

The region list often seems to be corrupted or to fail, this causes bad data to go into this line:

this.regions = Converters.PtrToClassArray<PARTY_REGION, Interop.PARTY_REGION>(
  stateChangeConverted.regions,
  regionCount,
  (x) => new PARTY_REGION(x));

Which then causes an Overflow of OutOfMemory exception in PtrToClassArray because the count is a huge invalid number:

ClassType[] ret = new ClassType[(Int32)count];

For now I am checking the count and protecting against this, but it seems there is a deeper issue here.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Unfortunately, I was not able to reproduce those "strange" errors you mentioned above, may I have more details about them and possibly some steps to reproduce them?

0 Likes 0 ·
Matthew Tighe avatar image
Matthew Tighe answered

Hi Citrus,

Those errors happen on every network connection if you use the XBL login provider. I discovered that region data is always just totally corrupt. Once in a while I get an error saying the region data could not be retrieved (especially after a network disconnect).

I discovered the region data is not actually used, so I simply remove all of this, the exception and crashes go away.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

So it might relate to the XBL SDK you're using, for that I'd suggest you open a thread in the XBOX forum for professional helps:)

0 Likes 0 ·
Matthew Tighe avatar image Matthew Tighe Citrus Yan commented ·

Sorry, do you mean a Playfab specific Xbox forum (if so where do I find that). Or the standard Xbox forums (not sure how this would help as it's certainly a Playfab issue)?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Matthew Tighe commented ·

Yes, I meant the Xbox Developer forum. Since you're using Party with XBOX GDK, you'd get more professional helps from there.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.