fitialovks / NoLiteDbForMe

Unity3D 2017.2 incompatibility with LiteDB 4.0.0
0 stars 0 forks source link

Baby-steps to reproduce #1

Open mbdavid opened 7 years ago

mbdavid commented 7 years ago

Hi, I'm a completely "null" in Unity but I want reproduce this error. What I did:

1- Using VS installer, select Unity and install 2- Create an Unity account (Personal) and open your root folder as an Unity Project. 3- Open "Assests/Editor" folder and double click in TheTest file 4- Now VS are open and I can see you code. Added a breakpoint in string dbFile = Path.GetTempFileName()

And now? I tried click in "Attach in Unity" or "Attach in Unity and Play".... an nothing. I saw it's a Unit test using NUnit. I installed "NUnit 3 Test Adapter" but still not showing this test in "Test Explorer".

Any tips?

fitialovks commented 7 years ago

To enable debugger use "Attach to Unity" button in VS. It simply attaches the debugger to Unity editor process and allows you to debug any code in the project. Does not matter if it is a test or a game script, all you need is to invoke it somehow in Unity.

To run the test use Unity itself. Window -> Test Runner to open the test list, then use Run All or just double click it there. It's an edit mode test, so make sure you are on EditMode tab there as opposed to PlayMode. Here is a link to their docs https://docs.unity3d.com/Manual/testing-editortestsrunner.html

I remember running some tests with ReSharper, but it does not work for me anymore. It also never worked with all tests either, most Unity code requires Unity runtime which is their own version of Mono.

mbdavid commented 7 years ago

Thanks, now it's possible to run and found the problem. It's really strange, because this "Text" index are not working. If a add a breakpoint just before your Text query, open Shell tool, read database, all data are there and query doesn't work too (return null). If I drop index and re-created (in shell) you and back again to VS, continue with your example, your document are found.

Any chance to debug LiteDB inside this code (using pdb)?

fitialovks commented 7 years ago

Debugger did not work for me. It works fine in Unity scripts, but stepping into the DLL breaks it.

mbdavid commented 7 years ago

Hi @fitialovks, I got the error... take a look on https://github.com/mbdavid/LiteDB/issues/734#issuecomment-344107860

fitialovks commented 7 years ago

Yep, thanks! There is another problem that you should know. Unity has IL2CPP compilation mode for Android (optional) and something similar for iOS (mandatory). That does not support reflection. I was unable to run LiteDB in that mode at all. I can help you set it up if you are determined to have full Unity3D support.

mbdavid commented 7 years ago

There is no reflection at all or Emit only? I removed Emit use to run on Unity. What option we have to avoid reflection?

fitialovks commented 7 years ago

I am not really sure what is supported, so I tried running it on Android.

  1. .NET 2.0 subset with Mono runtime fails at runtime, there is no FileStream constructor. See https://docs.unity3d.com/401/Documentation/ScriptReference/MonoCompatibility.html
    <i>AndroidPlayer(ADB@127.0.0.1:34999)</i> MissingMethodException: Method not found: 'System.IO.FileStream..ctor'.
    at LiteDB.FileDiskService.Initialize (LiteDB.Logger log, System.String password) [0x00000] in <filename unknown>:0 
    at LiteDB.LiteEngine..ctor (IDiskService disk, System.String password, Nullable`1 timeout, Int32 cacheSize, LiteDB.Logger log, Boolean utcDate) [0x00000] in <filename unknown>:0 
    UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    UnityEngine.DebugLogHandler:LogException(Exception, Object)
    UnityEngine.Logger:LogException(Exception, Object)
    UnityEngine.Debug:LogException(Exception)
    UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:265)
    UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:318)
    UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:228)
    UnityEngine.EventSystems.StandaloneInputModule:Process() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:211)
    UnityEngine.EventSystems.EventSystem:Update() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:294)

    This is probably as expected.

  2. .NET 2.0 with Mono runtime seems to work fine.
  3. .NET 2.0 with IL2CPP fails to link:
    Fatal error in Unity CIL Linker
    Mono.Linker.MarkException: Error processing method: 'System.Void LiteDB.LiteDatabase::.ctor(System.String,LiteDB.BsonMapper,LiteDB.Logger)' in assembly: 'LiteDB.dll' ---> System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
    at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
    at Mono.Cecil.Metadata.GuidHeap.Read(UInt32 index)
    at Mono.Cecil.MetadataReader.InitializeCustomDebugInformations()
    at Mono.Cecil.MetadataReader.GetCustomDebugInformation(ICustomDebugInformationProvider provider)
    at Mono.Cecil.Cil.PortablePdbReader.Read(MethodDefinition method)
    at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
    at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
    at Mono.Cecil.MethodDefinition.<>c.<get_Body>b__41_0(MethodDefinition method, MetadataReader reader)
    at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
    at Mono.Cecil.MethodDefinition.get_Body()
    at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
    at UnityLinker.Steps.UnityMarkStep.ProcessMethod(MethodDefinition method)
    at Mono.Linker.Steps.MarkStep.ProcessQueue()
    --- End of inner exception stack trace ---
    at Mono.Linker.Steps.MarkStep.ProcessQueue()
    at Mono.Linker.Steps.MarkStep.ProcessEntireQueue()
    at Mono.Linker.Steps.MarkStep.Process()
    at UnityLinker.Steps.UnityMarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at UnityLinker.UnityDriver.Run()
    at UnityLinker.UnityDriver.RunDriver()

    I have no clue what went wrong here.

fitialovks commented 7 years ago

I updated master branch with my test scene, new dll and configuration for Android build.

fitialovks commented 7 years ago

Sent them a bug report with this repository and links to our descussions.