facebook / facebook-sdk-for-unity

The facebook sdk for unity.
https://developers.facebook.com/docs/unity
Other
487 stars 256 forks source link

NullReferenceException inside Facebook.Unity.FacebookBase.API #534

Open NeroDocx opened 3 years ago

NeroDocx commented 3 years ago

Checklist

Environment

Goals

I want to get the player ID after login and restart the game.

Expected Results

Сallback should occur in FB.API if FB.IsLoggedIn is true. I want not to get NullReferenceException: Object reference not set to an instance of an object. Facebook.Unity.FacebookBase.API after successful login.

Actual Results

I use the login "FB.Mobile.LoginWithTrackingPreference" on the iOS device. After login, OnLoginResult is called. I restart the game and call "FB.API (" me? Fields = id ", HttpMethod.GET, OnPublicProfileGet)". After that, an error occurs on the device.

stack trace: NullReferenceException: Object reference not set to an instance of an object. Facebook.Unity.FacebookBase.API (System.String query, Facebook.Unity.HttpMethod method, System.Collections.Generic.IDictionary2 [TKey, TValue] formData, Facebook.Unity.FacebookDelegate1 [T] callback) (at <00000000000000000000000000000000>: 0) FacebookManager + d__12.MoveNext () (at <00000000000000000000000000000000>: 0) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00000000000000000000000000000000>: 0)

Steps to Reproduce

Steps:

Code Samples & Details

public void Initialize() {
    var go = new GameObject();
    DontDestroyOnLoad(go);
    go.name = "FacebookManager";
    go.AddComponent<FacebookManager>();

    FB.Init(AppId, clientToken, true, true, true, false, true, null, "en_US", null, OnInitComplete);
}

private void OnInitComplete() {
    if (FB.IsLoggedIn) {
        FB.LogAppEvent(AppEventName.ActivatedApp);
        StartCoroutine(Instance.UpdatePlayerIdTasks());
    }
}

private IEnumerator UpdatePlayerIdTasks() {
    yield return null;
    if (FB.IsLoggedIn) {
        FB.API("me?fields=id", HttpMethod.GET, OnPublicProfileGet);
    }
}
sebastian-dudzic-spl commented 1 year ago

We're experiencing exactly the same issue. A lot of null refs on prod. Any updates? @NeroDocx was it fixed for you? Or do you have a workaround?

Our version is Unity FB SDK - 15.1

sanuzzi commented 1 month ago

Same here. Unity 2021.3.36f1 Facebook SDK 17.0.1

The error only occurs on iOS On Android it works fine

aliyce commented 1 month ago

Exactly the same issue with @sanuzzi

nanddo commented 1 day ago

Having similar errors in production with the following set-up:

Similarly to @sanuzzi, the issue only happens on iOS, mostly on iPads (as seen in the screenshot below)

Error on Crashlytics:

Non-fatal Exception: NullReferenceException
0  ???                            0x0 API (Facebook.Unity.FacebookBase)

Facebook SDK issue