vovgou / loxodon-framework

An MVVM & Databinding framework that can use C# and Lua to develop games
MIT License
1.86k stars 363 forks source link

Android IL2CPP Weak References error #16

Closed batonPiotr closed 3 years ago

batonPiotr commented 3 years ago

Hello!

I have following issue: I bind a very simple view with one button:

dataContext = new MainMenuViewModel(commandDelay);
this.SetDataContext(dataContext);

/* databinding */
BindingSet<MainMenuViewController, MainMenuViewModel> bindingSet = this.CreateBindingSet<MainMenuViewController, MainMenuViewModel>();
bindingSet.Bind(this.runButton).For(v => v.onClick).To(vm => vm.OnRun).OneWay();

bindingSet.Build();

OnRun in this case is a simple public void method in the MainMenuViewModel. It works just fine in the editor but when I compile it to android I get following error:

2020-07-12 22:25:45.695 [ERROR] BindingSetBase - Loxodon.Framework.Binding.BindingException: An exception occurred while building the data binding for {binding onClick Path:OnRun Mode:OneWay }. ---> System.NotSupportedException: /Applications/Unity/2019.3.0f5/Unity.app/Contents/il2cpp/libil2cpp/gc/GCHandle.cpp(183) : Unsupported internal call for IL2CPP:GCHandle::NewWeakref - "IL2CPP does not support resurrection for weak references. Pass the trackResurrection with a value of false."
  at System.Runtime.InteropServices.GCHandle.Alloc (System.Object value, System.Runtime.InteropServices.GCHandleType type) [0x00000] in <00000000000000000000000000000000>:0 
  at System.WeakReference.AllocateHandle (System.Object target) [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.AbstractBinding..ctor (Loxodon.Framework.Binding.Contexts.IBindingContext bindingContext, System.Object dataContext, System.Object target) [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.Binding..ctor (Loxodon.Framework.Binding.Contexts.IBindingContext bindingContext, System.Object source, System.Object target, Loxodon.Framework.Binding.BindingDescription bindingDescription, Loxodon.Framework.Binding.Proxy.Sources.ISourceProxyFactory sourceProxyFactory, Loxodon.Framework.Binding.Proxy.Targets.ITargetProxyFactory targetProxyFactory) [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.BindingFactory.Create (Loxodon.Framework.Binding.Contexts.IBindingContext bindingContext, System.Object source, System.Object target, Loxodon.Framework.Binding.BindingDescription bindingDescription) [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.Contexts.BindingContext.Add (System.Object target, Loxodon.Framework.Binding.BindingDescription description, System.Object key) [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.Builder.BindingBuilderBase.Build () [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.Builder.BindingSetBase.Build () [0x00000] in <00000000000000000000000000000000>:0 
  at IslandRunner.UI.MainMenuViewController.<Start>b__3_0 () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at Run+<_RunAfter>d__9.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 
   --- End of inner exception stack trace ---
  at Loxodon.Framework.Binding.Builder.BindingBuilderBase.Build () [0x00000] in <00000000000000000000000000000000>:0 
  at Loxodon.Framework.Binding.Builder.BindingSetBase.Build () [0x00000] in <00000000000000000000000000000000>:0 
  at IslandRunner.UI.MainMenuViewController.<Start>b__3_0 () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
  at Run+<_RunAfter>d__9.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 
Loxodon.Framework.Binding.Builder.BindingSetBase:Build()
IslandRunner.UI.MainMenuViewController:<Start>b__3_0()
System.Action:Invoke()
<_RunAfter>d__9:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

It must have been because of the newest update. I've used this case before without problems in older versions but I cannot recall which one was it.

vovgou commented 3 years ago

Thank you very much! I have fixed this bug, please use version 1.9.12.

batonPiotr commented 3 years ago

It has solved the issue, thank you!