firebase::database::MutableData bug
feixuwu opened this issue · 6 comments
firebase::database::MutableData have too many bugs,
for example:
a simple test, in transaction function:
std::vectorfirebase::database::MutableData xxList;
xxList.push_back(data->Child("xxsdd") );
xxList[0].set_value("aaaa");
then will crash, seems like if I keep the MutableData on heap memory, then will crash.
Thanks for posting! I'll investigate whether this is a valid use case for MutableData and will post again shortly.
Just to be sure, could you paste your call stack (if you get one)?
I don't believe you can create new MutableData instances on the stack or heap, even within a transaction handler. Copying MutableData instances is also not allowed (although I believe we should add a move constructor and move operator, which will help you with your example).
As a workaround, use mutable_data->Child("xxsdd") to access the MutableData at the child path. If you modify a child's data, it will be visible to the parent. If you need to set a vector or map of data, use Variant's vector and map capabilities.
So for example, if you wanted to create a vector child inside a transaction handler with mutable_data as the parameter:
firebase::Variant vect = firebase::Variant::EmptyVector();
vect.vector()->push_back("aaaa");
mutable_data->Child("xxsdd").set_data(vect);
This will set the transaction data's "xxsdd" child to a vector, with the 0th entry of that vectr being "aaaa".
There are other (but similar) ways to use Variant to accomplish this and other tasks; see the firebase::Variant documentation for more information.
You could also get the MutableData contents as a Variant and play around with it like that:
firebase::Variant data = mutable_data->value();
/* change data as needed */
mutable_data->set_value(data);
Hope this helps! I'll leave this issue open until we add that move constructor/operator.
thanks for your reply,
I'm try to create a firebase plugin for unreal engine 4, both c++ and blueprint,
After several days struggle for this problem,
I guess the MutableData can not copy,
here is my test code,
I create a class to wrapper the MutableData, so I need to use a member to hold the MutableData, and here is the wrapper Child function:
std::string strPath = TCHAR_TO_UTF8(*path);
firebase::database::MutableData result = mMutableData->Child(strPath);
UFirebaseMutableData* ret = NewObject();
ret->mMutableData = TSharedPtrfirebase::database::MutableData(new firebase::database::MutableData(result) );
because the MutableData did not private it's copy constructor function, so I can copy.
the crash call stack:
10-04 08:31:16.400 32591-32591/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-04 08:31:16.403 32591-32591/? A/DEBUG: Build fingerprint: 'Xiaomi/capricorn/capricorn:7.0/NRD90M/7.9.21:user/release-keys'
10-04 08:31:16.403 32591-32591/? A/DEBUG: Revision: '0'
10-04 08:31:16.403 32591-32591/? A/DEBUG: ABI: 'arm'
10-04 08:31:16.404 32591-32591/? A/DEBUG: pid: 32267, tid: 32590, name: FirebaseDatabas >>> com.google.firebase.quickstart.auth <<<
10-04 08:31:16.404 32591-32591/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
10-04 08:31:16.404 32591-32591/? A/DEBUG: r0 c2f57000 r1 c19a42a4 r2 00000000 r3 00000000
10-04 08:31:16.404 32591-32591/? A/DEBUG: r4 c2f57000 r5 c19a42c8 r6 c2f5f960 r7 c4dc2170
10-04 08:31:16.404 32591-32591/? A/DEBUG: r8 c19a4750 r9 c4dc2170 sl 00000000 fp c19a4318
10-04 08:31:16.404 32591-32591/? A/DEBUG: ip d1c88180 sp c19a4298 lr d0fc1e63 pc d0fc1e1e cpsr 400d0030
10-04 08:31:16.425 32591-32591/? W/debuggerd: type=1400 audit(0.0:10087): avc: denied { search } for name="com.google.firebase.quickstart.auth" dev="dm-1" ino=2221450 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
10-04 08:31:16.435 32591-32591/? A/DEBUG: backtrace:
10-04 08:31:16.435 32591-32591/? A/DEBUG: #00 pc 06644e1e /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN8firebase4util19AttachCurrentThreadEP7_JavaVMPP7_JNIEnv+5)
10-04 08:31:16.435 32591-32591/? A/DEBUG: #1 pc 06644e5f /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN8firebase4util19GetThreadsafeJNIEnvEP7_JavaVM+38)
10-04 08:31:16.435 32591-32591/? A/DEBUG: #2 pc 0663fb21 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZNK8firebase3App9GetJNIEnvEv+4)
10-04 08:31:16.435 32591-32591/? A/DEBUG: #3 pc 0664d721 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN8firebase8database8internal19MutableDataInternal8SetValueENS_7VariantE+12)
10-04 08:31:16.435 32591-32591/? A/DEBUG: #4 pc 06648225 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN8firebase8database11MutableData9set_valueENS_7VariantE+18)
10-04 08:31:16.436 32591-32591/? A/DEBUG: #5 pc 055a70e4 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN20UFirebaseMutableData9set_valueEP16UFirebaseVariant+72)
10-04 08:31:16.436 32591-32591/? A/DEBUG: #6 pc 055b79c8 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN20UFirebaseMutableData13execset_valueER6FFramePv+108)
10-04 08:31:16.436 32591-32591/? A/DEBUG: #7 pc 023d6230 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN9UFunction6InvokeEP7UObjectR6FFramePv+124)
10-04 08:31:16.436 32591-32591/? A/DEBUG: #8 pc 02543e34 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN7UObject12CallFunctionER6FFramePvP9UFunction+8896)
10-04 08:31:16.436 32591-32591/? A/DEBUG: #9 pc 0254f31c /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN7UObject20ProcessContextOpcodeER6FFramePvb+416)
10-04 08:31:16.437 32591-32591/? A/DEBUG: #10 pc 02545128 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN7UObject15ProcessInternalER6FFramePv+3564)
10-04 08:31:16.437 32591-32591/? A/DEBUG: #11 pc 023d6230 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN9UFunction6InvokeEP7UObjectR6FFramePv+124)
10-04 08:31:16.437 32591-32591/? A/DEBUG: #12 pc 02548df4 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN7UObject12ProcessEventEP9UFunctionPv+5360)
10-04 08:31:16.437 32591-32591/? A/DEBUG: #13 pc 055af2e0 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so
10-04 08:31:16.437 32591-32591/? A/DEBUG: #14 pc 0664f141 /data/app/com.google.firebase.quickstart.auth-1/lib/arm/libUE4.so (_ZN8firebase8database8internal9Callbacks31TransactionHandlerDoTransactionEP7_JNIEnvP7_jclassxxP8_jobject+54)
10-04 08:31:16.437 32591-32591/? A/DEBUG: #15 pc 000008f1 /data/data/com.google.firebase.quickstart.auth/code_cache/database_resources_lib.dex (offset 0x3000)
By the way, because the firebase c++ windows lib is build with single thread static,
so with my project, windows will link error(I know it will not work on desktop),
I need to use a lot of #ifdef to make the code both compile on desktop and android.
if can add the MDD and MD version will be perfect.
it's ok
We have fixed both the crash and the windows linkage issues in Firebase C++ 4.4.2.
https://firebase.google.com/support/release-notes/cpp-relnotes#4.4.2