Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [8.5.0] [iOS] Firestore crash when snapshot listener being used #1174

Closed
npicouet opened this issue Nov 3, 2021 · 2 comments
Closed

Comments

@npicouet
Copy link

npicouet commented Nov 3, 2021

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.5f1
  • Firebase Unity SDK version: 8.5.0
  • Source you installed the SDK: Local .tgz
  • Problematic Firebase Component: Firestore
  • Other Firebase Components in use: Everything
  • Additional SDKs you are using: Facebook, Apple Sign In, Google Sign In, Unity Ads, Unity Purchasing
  • Platform you are using the Unity editor on: Mac M1
  • Platform you are targeting: iOS
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the issue here:

The app crashes on iOS during my ListenServerVersion() function call.
The function is listening for a Firestore snapshot.

This has only started happening as of 8.5.0. It was working fine in previous versions.

Steps to reproduce:

Try to listen to a document snapshot during the firebase startup dependency check.

Relevant Code:

This is the startup code. The problematic function is called near the end of the startup sequence.

void StartFirebase()
	{
		//Check Dependencies
		Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
		{
			var dependencyStatus = task.Result;
			if (dependencyStatus == Firebase.DependencyStatus.Available)
			{
				//Dynamic Links
				DynamicLinks.DynamicLinkReceived += OnDynamicLink;

				//App Reference
				appRef = Firebase.FirebaseApp.DefaultInstance;

				//Authentication Reference
				authRef = Firebase.Auth.FirebaseAuth.DefaultInstance;

				//Firestore Reference
				firestoreRef = FirebaseFirestore.DefaultInstance;

				//Realtime Database Reference
				databaseRef = FirebaseDatabase.DefaultInstance;

				//Storage Reference
				storageRef = FirebaseStorage.DefaultInstance.RootReference;

				//Function Reference
				functionRef = FirebaseFunctions.DefaultInstance;

				//Get Remote Config Reference
				remoteConfigRef = Firebase.RemoteConfig.FirebaseRemoteConfig.DefaultInstance;

				//Set Initialized
				IsFirebaseInitialized = true;

				//Setup Remote Config
				SetupRemoteConfig();

				//Listen for Server Version
				ListenServerVersion();

				Debug.Log("Firebase Initialized!");
			}
			else
			{
				UnityEngine.Debug.LogError(System.String.Format(
					"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
				// Firebase Unity SDK is not safe to use here.
			}
		});
	}

This is the function in question:

///Listen Server Version
	void ListenServerVersion()
	{
		DocumentReference docRef = firestoreRef.Collection("server").Document("info");
		versionListener = docRef.Listen(snapshot =>
		{
			//Get Snapshot
			Dictionary<string, object> dict = snapshot.ToDictionary();

			//Check Server Version
			int version = int.Parse(dict["version"].ToString());

			//Update State
			print("Check Server Version: " + version + " == " + SaveManager.ServerVersion);
			if (version == SaveManager.ServerVersion)
			{
				//Continue
				print("Server Version Verified!");
				IsFirebaseVerified = true;
				HideInfo();
			}
			else
			{
				print("Server Version Mismatch!");
				IsFirebaseVerified = false;
				ShowInfo(CuriousLocalization.GetLocalizedString("error-app-maintenance") + "\n" + CuriousLocalization.GetLocalizedString("error-app-update"), 0.5f);
				SaveManager.SplashSeen = false;
				LoadController.instance.LoadScene("Login");
			}
		});
	}

This is the log from xCode:

2021-11-03 11:42:13.041743-0600 DoodleParty[347:11616] WF: _WebFilterIsActive returning: NO
Unexpected exception thrown by DocumentSnapshotsHandler() when invoked by P/Invoke: System.NullReferenceException: Object reference not set to an instance of an object.
  at FirebaseManager.<ListenServerVersion>b__262_0 (Firebase.Firestore.DocumentSnapshot snapshot) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action`1[T].Invoke (T obj) [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Firestore.DocumentReference+<Listen>c__AnonStorey0+<Listen>c__AnonStorey1.<>m__0 () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Func`1[TResult].Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Dispatcher.Run[TResult] (System.Func`1[TResult] callback) [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Platform.FirebaseHandler.RunOnMainThread[TResult] (System.Func`1[TResult] f) [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Firestore.DocumentReference+<Listen>c__AnonStorey0.<>m__0 (Firebase.Firestore.DocumentSnapshotProxy snapshotProxy, Firebase.Firestore.FirestoreError errorCode, System.String errorMessage) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action`3[T1,T2,T3].Invoke (T1 arg1, T2 arg2, T3 arg3) [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Firestore.DocumentReference.DocumentSnapshotsHandler (System.Int32 callbackId, System.IntPtr snapshotPtr, Firebase.Firestore.FirestoreError errorCode, System.String errorMessage) [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.AppUtilPINVOKE.Firebase_App_PollCallbacks () [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.AppUtil.PollCallbacks () [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Platform.FirebaseAppUtils.PollCallbacks () [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Platform.FirebaseHandler.Update () [0x00000] in <00000000000000000000000000000000>:0 
  at Firebase.Platform.FirebaseMonoBehaviour.Update () [0x00000] in <00000000000000000000000000000000>:0 
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
Firebase.Platform.FirebaseLogger:LogMessage(PlatformLogLevel, String)
Firebase.LogUtil:LogMessage(LogLevel, String)
Firebase.Firestore.Internal.Util:OnPInvokeManagedException(Exception, String)
Firebase.Firestore.DocumentReference:DocumentSnapshotsHandler(Int32, IntPtr, FirestoreError, String)
Firebase.AppUtilPINVOKE:Firebase_App_PollCallbacks()
Firebase.AppUtil:PollCallbacks()
Firebase.Platform.FirebaseAppUtils:PollCallbacks()
Firebase.Platform.FirebaseHandler:Update()
Firebase.Platform.FirebaseMonoBehaviour:Update()
@dconeybe
Copy link

dconeybe commented Nov 3, 2021

Unfortunately, this is a known issue that snuck into the 8.5.0 release. We have a fix for it in the next release whose ETA is roughly 2 weeks from now. The only workaround is to downgrade the Unity SDK. Please see this duplicate issue for more details: #1171

@dconeybe dconeybe closed this as completed Nov 3, 2021
@dconeybe
Copy link

dconeybe commented Nov 9, 2021

The fix was just released in the Firebase Unity SDK 8.6.0.

@firebase firebase locked and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants