Ap6661 / LaserRecolorJank

A NeosModLoader mod that allows custom laser color and cursor
MIT No Attribution
2 stars 2 forks source link

OnConfigurationUpdate Fails to update Current Colors and Vars #5

Open zahndy opened 3 weeks ago

zahndy commented 3 weeks ago

When I tried this in a different project I would get exceptions so I wondered if this mod also suffers from the same thing. And I guess it does as my log is full of the same errors.

16:40:00.063 (144 FPS)  [ERROR][ResoniteModLoader] An OnThisConfigurationChanged event subscriber threw an exception:
System.AggregateException: One or more errors occurred. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Modifications from a non-locking thread are disallowed! Current lock: DataModel
  at FrooxEngine.ConnectorManager.ThreadCheck () [0x00026] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.SyncElement.BeginModification (System.Boolean throwOnError) [0x00055] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.SyncField`1[T].InternalSetValue (T& value, System.Boolean sync, System.Boolean change) [0x00000] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.SyncField`1[T].set_Value (T value) [0x0006e] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.Sync`1[T].set_Value (T value) [0x0000f] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at LaserRecolorJank.Patch.OnConfigurationUpdate (ResoniteModLoader.ConfigurationChangedEvent event) [0x0032c] in <3aac956b7fc74e29b730c7543edc6b35>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <9577ac7a62ef43179789031239ba8798>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <9577ac7a62ef43179789031239ba8798>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <9577ac7a62ef43179789031239ba8798>:0 
  at ResoniteModLoader.DelegateExtensions.SafeInvoke (System.Delegate del, System.Object[] args) [0x00021] in <16e726bf5d5c4684a50e80978c529d1d>:0 
   --- End of inner exception stack trace ---
  at ResoniteModLoader.DelegateExtensions.SafeInvoke (System.Delegate del, System.Object[] args) [0x0004e] in <16e726bf5d5c4684a50e80978c529d1d>:0 
  at ResoniteModLoader.ModConfiguration.FireConfigurationChangedEvent (ResoniteModLoader.ModConfigurationKey key, System.String label) [0x00053] in <16e726bf5d5c4684a50e80978c529d1d>:0 
---> (Inner Exception #0) System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Modifications from a non-locking thread are disallowed! Current lock: DataModel
  at FrooxEngine.ConnectorManager.ThreadCheck () [0x00026] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.SyncElement.BeginModification (System.Boolean throwOnError) [0x00055] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.SyncField`1[T].InternalSetValue (T& value, System.Boolean sync, System.Boolean change) [0x00000] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.SyncField`1[T].set_Value (T value) [0x0006e] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at FrooxEngine.Sync`1[T].set_Value (T value) [0x0000f] in <441220e9ea6e4e28827e9a4699cf0791>:0 
  at LaserRecolorJank.Patch.OnConfigurationUpdate (ResoniteModLoader.ConfigurationChangedEvent event) [0x0032c] in <3aac956b7fc74e29b730c7543edc6b35>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <9577ac7a62ef43179789031239ba8798>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <9577ac7a62ef43179789031239ba8798>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <9577ac7a62ef43179789031239ba8798>:0 
  at ResoniteModLoader.DelegateExtensions.SafeInvoke (System.Delegate del, System.Object[] args) [0x00021] in <16e726bf5d5c4684a50e80978c529d1d>:0 <---
Ap6661 commented 3 weeks ago

I have zero idea what causes this and it is inconsistent whether it works or no on different machines and doesnt on others

Nytra commented 3 weeks ago

You can't change the data model for a given world outside of the thread for that world, usually I get around this by using world.RunSynchronously(() => {your code here}) which will run that code in the correct thread for the world and avoids these errors