Litedb: Unity and WebGL compatible

Created on 18 Mar 2019  路  8Comments  路  Source: mbdavid/LiteDB

Hi.

Just wondering if anyone has had any luck getting the Unity Package to work on a Unity WebGL build for reading data from a database in streaming assets? Trying to get it working currently and can read the bytes, convert to memory stream and then use this to open the database. I am then able to view collection names but whenever i try and get data out i hit a memory error.

suggestion

Most helpful comment

I took a shot at porting LiteDB v5 to Unity, and the mapper getter/setter stuff is probably fixable, but I stopped working on it because it seems that in v5, nearly every query runs through C#'s compiled lambda expression code, which will never work with IL2CPP.

If you're interested in using LiteDB under Unity, take a look at the branch of LiteDB v4 that I'm working on. I'm gradually working v5 features into it, and is intended for use in Unity so I'm only adding things that can work in AoT environments.

https://github.com/rejemy/UltraLiteDB

All 8 comments

Just ran into the same problem, from the StackTrace it looks like the "BsonMapper_BuildEntityMapper" is calling a CreateGenericGetter method and somewhere there crashes:

exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds
    at __ZN16VirtFuncInvoker0IP6Type_tE6InvokeEjP12Il2CppObject (wasm-function[30944]:18)
    at _LightLambda_MakeRunDelegateCtor_m34176183E3A928A397721E889331C32DF9C556C1 (wasm-function[43248]:1487)
    at dynCall_iii (wasm-function[73889]:16)
    at Object.dynCall_iii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26549:38)
    at invoke_iii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:17870:31)
    at _LightLambda_GetRunDelegateCtor_m802F474EE5F98CB221B2E24609A743536CFF4517 (wasm-function[43246]:389)
    at _LightLambda_MakeDelegate_m5BF4647527466A602E0339000CBE3382BB98B4C0 (wasm-function[43245]:75)
    at _LightDelegateCreator_CreateDelegate_mAD897B269ED0186D1E2CEA54BFBD550375E072F6 (wasm-function[43243]:76)
    at _LightDelegateCreator_CreateDelegate_m1B6E2A2E3D20D75EB586A04B9F248208272329CC (wasm-function[43242]:7)
    at _Expression_1_Compile_m5F2BD4EE3DA1F051DDD2D1CF6B3467390FE06A39_gshared (wasm-function[65389]:68)
    at _Expression_1_Compile_m32BD954CB112E9E0054156346964AB1E410377CF_gshared (wasm-function[65388]:34)
    at __Z62Expression_1_Compile_m1FB0D36180E1B6DC47F68802D34167D780A5C338P54Expression_1_tB37C50B4E4CE8A441B6834EB04541A9B3D7EFF8DPK10MethodInfo (wasm-function[60469]:5)
    at _Reflection_CreateGenericGetter_mC38804D663E3223CEF6762889203F957811673B8 (wasm-function[72626]:427)
    at dynCall_iiii (wasm-function[73900]:18)
    at Object.dynCall_iiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26604:39)
    at invoke_iiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:17958:32)
    at _BsonMapper_BuildEntityMapper_m055071F8F04E659DE2B52B5852F47798F4C2F590 (wasm-function[60532]:1104)
    at __ZN16VirtFuncInvoker1IbP12Il2CppObjectE6InvokeEjS1_S1_ (wasm-function[30956]:48)
    at dynCall_iiii (wasm-function[73900]:18)
    at Object.dynCall_iiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26604:39)
    at invoke_iiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:17958:32)
    at _BsonMapper_GetEntityMapper_m0C474FAF7688D187B4A4C9ECDDBFD316A1729965 (wasm-function[60531]:250)
    at _LiteCollection_1__ctor_m25D52BEE978AA25FB6B787BB512AE456077A5226_gshared (wasm-function[64305]:578)
    at _LiteDatabase_GetCollection_TisRuntimeObject_mD2C4F0C29AC37244D24FAE47715543CF7AFB541A_gshared (wasm-function[59983]:79)
    at __Z122LiteDatabase_GetCollection_TisTreeElem_t579B24F7FB101E94ABCD2E1175E0C3399C797413_m32746F82B701BF9203CD9584A4926A96E750CB19P54LiteDatabase_t86EAC381EB5D0F5A34618932319926C1C0EC5E50P8String_tPK10MethodInfo (wasm-function[58913]:7)
    at dynCall_iiii (wasm-function[73900]:18)
    at Object.dynCall_iiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26604:39)
    at invoke_iiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:17958:32)
    at _LiteDbTests_ExampleUsage1_m75B4E8F376215CD0E3119246D60C06609E3E24A3 (wasm-function[58919]:307)
    at __Z65RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017PFvvEPK10MethodInfoPvPS4_ (wasm-function[55538]:17)
    at dynCall_iiiii (wasm-function[73908]:20)
    at Object.dynCall_iiiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26644:40)
    at invoke_iiiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:18022:33)
    at __ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException (wasm-function[51544]:175)
    at __ZN6il2cpp2vmL17InvokeConvertThisEPK10MethodInfoPvPS4_PP15Il2CppException (wasm-function[51562]:46)
    at __ZN6il2cpp2vm7Runtime17InvokeConvertArgsEPK10MethodInfoPvPP12Il2CppObjectiPP15Il2CppException (wasm-function[51561]:632)
    at __ZN6il2cpp2vm7Runtime11InvokeArrayEPK10MethodInfoPvP11Il2CppArrayPP15Il2CppException (wasm-function[51560]:37)
    at __ZN6il2cpp6icalls8mscorlib6System10Reflection10MonoMethod14InternalInvokeEP22Il2CppReflectionMethodP12Il2CppObjectP11Il2CppArrayPS8_ (wasm-function[52712]:357)
    at _MonoCMethod_InternalInvoke_m114B2C342EE10E62D405951BB8F4549D9E54A690 (wasm-function[46958]:9)
    at dynCall_iiiiii (wasm-function[73914]:22)
    at Object.dynCall_iiiiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26674:41)
    at invoke_iiiiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:18070:34)
    at _MonoMethod_Invoke_mD791F247764DAE0188BA06FD1DA51525E8F2F394 (wasm-function[47017]:211)
    at __ZN16VirtFuncInvoker5IP14PropertyInfo_tiP60PropertyInfoU5BU5D_tAD8E99B12FF99CA4F2EA37B612DE68E112B4CF7EP6Type_tP52TypeU5BU5D_t7FE623A666B49176DE123306221193E888A12F5FP65ParameterModifierU5BU5D_t63EC46F14F048DC9EF6BF1362E8AEBEA1A05A5EAE6InvokeEjP12Il2CppObjectiS3_S5_S7_S9_ (wasm-function[32140]:56)
    at _MethodBase_Invoke_m471794D56262D9DB5B5A324883030AB16BD39674 (wasm-function[46908]:15)
    at dynCall_iiiii (wasm-function[73908]:20)
    at Object.dynCall_iiiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:26644:40)
    at invoke_iiiii (blob:http://localhost:65257/532ec541-0fd6-42a4-b305-8302f3ffefcb:18022:33)
    at _XunitTestRunner_RunTestOnMethod_m50DA79C9DE437775F551C88420E80681FDF4D0C9 (wasm-function[50344]:66)
    at _U3CU3Ec__DisplayClass2_1_U3CGetIteratorOverAllTestsU3Eb__1_m53D657F42CDD0EAA56CE4F82509FCD7462379005 (wasm-function[50356]:78)

@mbdavid any hints if this is on some sort of roadmap to make LiteDB more compatible with Unity and WebGL builds?

Hi @cs-util, I will take a look on this problem in v5 build.

@mbdavid I saw you removed the v5 label, is there any news why the AOT platforms like WebGL have currently problems with LiteDB?

Hi @cs-util, I remove because master branch are current v5 version and all updates will be run over master. You still have problems with LiteDB in unity (final v5 version)? If true, please open an bug issue with an example (I'm not Unity programer - so if you create a simple project in unity with your error will be best). I'm very interested in resolve any Unity compatibility problem

@cs-util, sorry, I read "branch" not "label". But my anwser still same: I remove v5 label from all issues because I will identify only v4 because all others must be about v5.

I took a shot at porting LiteDB v5 to Unity, and the mapper getter/setter stuff is probably fixable, but I stopped working on it because it seems that in v5, nearly every query runs through C#'s compiled lambda expression code, which will never work with IL2CPP.

If you're interested in using LiteDB under Unity, take a look at the branch of LiteDB v4 that I'm working on. I'm gradually working v5 features into it, and is intended for use in Unity so I'm only adding things that can work in AoT environments.

https://github.com/rejemy/UltraLiteDB

@rejemy I just add in README a link for UltraLiteDB, thanks for this version!

Was this page helpful?
0 / 5 - 0 ratings