Open NeroDocx opened 3 years 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
Same here. Unity 2021.3.36f1 Facebook SDK 17.0.1
The error only occurs on iOS On Android it works fine
Exactly the same issue with @sanuzzi
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)
@NeroDocx @sanuzzi @aliyce @nanddo Did you guys find a solution to this issue? I'm facing the exact problem with FB SDK v14.1.0, v15.1.0, v16.0.2 and v17.0.1 and Unity 2022.3.34f1. I have no idea why this is happening. It was working perfectly before.
@chanchangame No solution yet, the crash keeps happening. The only possibility seems to be removing the Facebook SDK, which is far from ideal.
@nanddo I added some logs and it looks like on kill and launch, the AccessToken.CurrentAccessToken
becomes null. Maybe FB.API()
is using that internally to hit the Graph API. I don't know whether this is an expected behaviour. I checked FB.IsInitialized
and FB.IsLoggedIn
just before calling FB.API()
and both are returning true.
Hey @chanchangame thanks for the info. Were you able to bypass the null reference somehow (maybe adding a try catch
block whenever calling the FB.API()
?). Checking for FB.IsInitialized
and FB.IsLoggedIn
doesn't seem to solve the issue if I understood correctly.
@nanddo I found out that it was indeed because of empty access token. I was not able to directly fix it being empty in subsequent sessions, but I found a work around. Before calling FB.API()
method, I will check if AccessToken.CurrentAccessToken
is null. If it is null, then I will call FB.Mobile.RefreshCurrentAccessToken()
provided by the SDK and will wait for the result and then call FB.API()
. This way the access token will be refreshed and then the call will work.
But if you don't want to call RefreshCurrentAccessToken()
on every session, then you can check out this thread:
https://github.com/facebook/facebook-sdk-for-unity/issues/695
I wasn't able to test what @dvgco said at the end because of time constrains. You can give it a try if you want.
Checklist
Environment
2018.4.28f1
Facebook SDK Unity SDK 9.0.0
iOS
version12.0
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.IDictionary d__12.MoveNext () (at <00000000000000000000000000000000>: 0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00000000000000000000000000000000>: 0)
2 [TKey, TValue] formData, Facebook.Unity.FacebookDelegate
1 [T] callback) (at <00000000000000000000000000000000>: 0) FacebookManager +Steps to Reproduce
Steps:
2[TKey,TValue] formData, Facebook.Unity.FacebookDelegate
1[T] callback) on the device.Code Samples & Details