Closed vcLS132 closed 1 year ago
Based on the stack trace it looks like you are calling DocumentReference.Listen()
on a Firestore document. Then, in the listener callback, you are creating a DatabaseReference
in Realtime Database. The crash is happening in the creation of the Realtime Database reference. Are you aware that Firestore and Realtime Database, although similar in principle, are completely different database offerings from Firebase an are incompatible? If you are using Firestore then make sure to use Firestore classes and methods and not to accidentally use classes and methods from the Realtime Database API.
Hello, and thanks for the reply. So in short if I remove this code snippet DocumentReference DOCREF = FirebaseInitModified.Instance.firestoreDatabaseReference.Collection("GetSocialUsers").Document(firestoreDbId); from the callback, it should stop the crash. Right? But why is it not crashing on the first run when I install the application and only crashing when I reopen the application?
I'm not familiar enough with your code to confidently say what you need to change to fix the crash. For example, I don't know what FirebaseInitModified
is (is it a class defined in your application?). It looks like somewhere your app is calling DatabaseReference.Child(...)
. Could you log the value that you are specifying as the pathString
argument to DatabaseReference.Child(...)
and let us know what it is?
this is my FirebaseInitModified class. Is has this public FirebaseFirestore firestoreDatabaseReference;
public class FirebaseInitModified : MonoBehaviour { public static FirebaseInitModified Instance; private const string kUserId = "UserId"; public bool Initialized; [SerializeField] FirebaseNotificationController notificationController; public FirebaseApp firebaseApplication; public FirebaseFirestore firestoreDatabaseReference; public DatabaseReference databaseReferenceObject; public FirebaseCloudStorageManager gameObject_FirebaseCloudStorageManager;
private void Awake()
{
//Debug.Log($"FirebaseInitModified AWAKE START ");
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(this.gameObject);
return;
}
Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
FirebaseApp.CheckDependenciesAsync().ContinueWithOnMainThread(task =>
{
var dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available && !Initialized)
{
firebaseApplication = FirebaseApp.DefaultInstance;
databaseReferenceObject = FirebaseDatabase.DefaultInstance.RootReference;
firestoreDatabaseReference = FirebaseFirestore.DefaultInstance;
firestoreDatabaseReference.Settings.PersistenceEnabled = false;
if (gameObject_FirebaseCloudStorageManager != null)
{
gameObject_FirebaseCloudStorageManager.gameObject.SetActive(true);
}
notificationController.CustomStart();
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
Crashlytics.IsCrashlyticsCollectionEnabled = true;
if (SceneManager.GetActiveScene().name == "MenuScene")
{
try
{
FirebaseDataController.instance.CustomStart();
}
catch (System.Exception)
{
FirebaseDataController dbController = FindObjectOfType<FirebaseDataController>();
if (dbController != null)
{
dbController.CustomStart();
}
}
}
Initialized = true;
}
else
{
Debug.LogError("Firebase Not Available");
}
});
}
} I have modified the ".Listen" code snippet by taking the DocumentReference DOCREF = FirebaseInitModified.Instance.firestoreDatabaseReference.Collection("GetSocialUsers").Document(firestoreDbId); as global so that I won't have to call it again when "Listen" callback is called.
Ok that is helpful. Nothing in that code sample looks suspicious. Can you also show the code that is calling DatabaseReference.Child(...)
?
also in the listen call back I am calling the firebase realtime database function to update certain data on realtime database as well. DatabaseReferenceObject.Child("Users").Child(Globals.userInfo.UserName).Child(TableName).SetRawJsonValueAsync(jsonData); but it does not happen often as it is bound by come conditions so triggering it on the second run is next to impossible. Also I was triggering a call
FirebaseInitModified.Instance.firestoreDatabaseReference.Collection("GetSocialUsers").Document(GsIdLoggedInUser).SetAsync(userPropertiesForGame) so I think this may also be responsible. As I have made this global so I'll try to make another build and see if it still crashes.
I can tell you with very high confidence from the stack trace in your opening comment that the crash is happening in a call to DatabaseReference.Child(...)
. The Firestore code never uses Realtime Database code, so the problematic call to DatabaseReference.Child(...)
must be one from your application.
What I recommend to do is to do Debug.LogError()
on the value of Globals.userInfo.UserName
and TableName
prior to each call of DatabaseReferenceObject.Child()
to see what values are being passed in. Then, you should be able to see, from the logs, what value was problematic.
ok, I'll try that. But DatabaseReferenceObject.Child() should not cause the issue as the crash is happening in the second scene where I am calling the .Listen for firestore and all the globals and references are assigned in the opening scene or first scene that way it loads game data from Firebase real-time database and if any changes are to be done to the Database then I call this code DatabaseReferenceObject.Child("Users").Child(Globals.userInfo.UserName).Child(TableName).SetRawJsonValueAsync(jsonData); Plus if the code DatabaseReferenceObject.Child was problematic wouldn't it cause the issue in the very first run? Rather that n in the second.
Without having seen your code I can't explain why the crash only occurs on subsequent launches. The crash message does say that
Must be a non-empty string and not contain '.' '#' '$' '[' or ']'
So perhaps on the second launch Globals.userInfo.UserName
and/or TableName
are either empty or contain one of those illegal characters, causing the crash.
It's also possible that the stack trace from the opening comment is a different crash. What would be really helpful would be a minimal app that reproduces the crash. Then I could reproduce the crash for myself and investigate. I realize that's a pretty large undertaking but if you're willing to produce something like that and share it then it could be very helpful. But let's see what we learn from the log output first.
I may have found the Must be a non-empty string and not contain '.' '#' '$' '[' or ']' this part. I have this function public void CheckForFirestoreTransfer() { if (On_EventCheckForFirestoreTransfer != null) { On_EventCheckForFirestoreTransfer -= CheckForFirestoreTransfer; } if (On_IfAutoOverrideTakesPlaceWIthoutPopUp != null) { On_IfAutoOverrideTakesPlaceWIthoutPopUp -= CheckForFirestoreTransfer;//+ }
//^Debug.Log($"CheckForFirestoreTransfer");
FirebaseDataController.instance.DatabaseReferenceObject.Child("Users").
Child(FirebaseDataController.instance.FacbookToken).Child("DataOverride").
GetValueAsync().ContinueWithOnMainThread(task =>
{
if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
if (snapshot.Exists)
{
string jsonValue = snapshot.GetRawJsonValue();
//^Debug.Log($"CheckForFirestoreTransfer EXISTS jsonValue {jsonValue}");
Globals.dataOverride = JsonConvert.DeserializeObject<DataOverride>(jsonValue);
if (Globals.dataOverride.isOverrideDone)
{
//^Debug.Log($"isOverrideDone {Globals.dataOverride.isOverrideDone}");
TransferFirestore();
if (Globals.dataOverride.friendsExist)
{
//^Debug.Log($"friendsExist");
if (Globals.dataOverride.friendsToAdd.Count >= 1)
{
friendsToTransfer.Clear();
friendsToTransfer = Globals.dataOverride.friendsToAdd.ToList();
AddFriends_TransferGetSocial();
}
}
FirebaseDataController.instance.DatabaseReferenceObject.Child("Users").
Child(FirebaseDataController.instance.FacbookToken).Child("DataOverride").RemoveValueAsync();
Globals.dataOverride = new DataOverride();
//^Debug.Log($"Globals.dataOverride CLEARED");
}
}
}
});
}
this is from the snipped I present in the opening
On_EventCheckForFirestoreTransfer += CheckForFirestoreTransfer;
and in the call back I am doing this
public void Subscriber_fsListnerCallback(DocumentSnapshot snapshot)
{
Debug.Log($"Subscriber_fsListnerCallback");
userPropertiesForGame = snapshot.ConvertTo
I don't understand your application well enough to speculate on what may be going wrong. I still think the cause of the crash is invoking DatabaseReference.Child(...)
with a string whose value is not valid. Can you try logging the strings that you are specifying to DatabaseReference.Child(...)
to see if any of them happen to be invalid immediately before the crash?
ok, I'll try the logging method and will let you know.
ok, I'll try the logging method and will let you know.
After applying logs at every step and thoroughly debugging, I found a call at DatabaseReference.Child() was looking for an empty/non-existent child, so it was crashing on ios. Surprisingly same logic and code were not crashing on Android even for the empty/non-existent child. So I applied a simple boolean check and it fixed the crash issue.
Thank you @dconeybe for all the help as I was unable to understand the main issue just by looking at the crash logs.
Oh that's great! Thanks for the update and I'm glad you're unblocked.
[REQUIRED] Please fill in the following fields:
[REQUIRED] Please describe the issue here:
Only the iOS application crashes on the second run when firestore document listener a.k.a "docRef.Listen" is called. When I reinstall the application and open it for the first time there are no crashes and everything works as it should. Now I close the application and remove it from the recent applications list also. Now when I open it again and make the call for "docRef.Listen" it crashes. Crash reported by the crashlytics is Fatal Exception: InvalidPathValidation (child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']' Crashed: com.google.firebase.crashlytics.ios.exception SIGABRT ABORT 0x000000020b0ed674 The document that I am trying to access is also present as it can be accessed in the first run and if any changes are made to document data they are also listened by the listener in the application also so everything is working smoothly in the first run. NOTE:- Android application with same code and same everything is not crashing in any scenario. (Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)
Steps to reproduce:
Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate? (eg 100%, 1/5 etc)
What happened? How can we make the problem occur? This could be a description, log/console output, etc.
If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.
Relevant Code: