0
Fixed

Reloading assemblies during play mode corrupts Macro and Variables / data

Pawel Lewandowski 3 weeks ago • updated by Lazlo Bonin (Lead Developer) 2 weeks ago 5 1 duplicate

I just write new topic about that bug becouse  I see that old one is closed. We still have a issue with self deleting Varaiables and macros from flow/state machines. I will post here my repro steps and stack.

1. Open unity
2. Go to play mode
3. Attach debuger
4. After attaching debuger  I see error in console from object that have a state/flow machine
5. I see that this object have all macros and variables
6. Stop play mode
7. Now all variables and macros gone



Failed to deserialize behaviour.
System.Runtime.Serialization.SerializationException:
Deserialization into 'Bolt.StateMachine' failed. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> System.ArgumentNullException:
Value cannot be null.

Parameter name: instance

at
Ludiq.EnsureThat.IsNotNull[T] (T value) [0x00010] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Ensure\EnsureThat.Objects.cs:29


at Ludiq.GraphInstances.Instantiate (Ludiq.GraphReference
instance) [0x00010] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Graphs\Runtime\GraphInstances.cs:20


at Ludiq.Machine`2[TGraph,TMacro].InstantiateNest ()
[0x00008] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Graphs\Runtime\Machines\Machine.cs:169


at Ludiq.GraphNest`2[TGraph,TMacro].AfterGraphChange ()
[0x0001e] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Graphs\Runtime\GraphNest.cs:170


at Ludiq.GraphNest`2[TGraph,TMacro].set_macro (TMacro value)
[0x00026] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Graphs\Runtime\GraphNest.cs:57


at
Ludiq.InstancePropertyAccessor`2[TTarget,TProperty].SetValueUnsafe
(System.Object target, System.Object value) [0x00000] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Reflection\Optimization\InstancePropertyAccessor.cs:144


at
Ludiq.InstancePropertyAccessor`2[TTarget,TProperty].SetValue
(System.Object target, System.Object value) [0x000b2] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Reflection\Optimization\InstancePropertyAccessor.cs:125


--- End of inner exception stack trace ---

at
Ludiq.InstancePropertyAccessor`2[TTarget,TProperty].SetValue
(System.Object target, System.Object value) [0x000c0] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Reflection\Optimization\InstancePropertyAccessor.cs:133


at Ludiq.OptimizedReflection.SetValueOptimized
(System.Reflection.PropertyInfo propertyInfo, System.Object target,
System.Object value) [0x00000] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Reflection\Optimization\OptimizedReflection.cs:196


at Ludiq.FullSerializer.fsMetaProperty.Write (System.Object
context, System.Object value) [0x00052] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\Reflection\fsMetaProperty.cs:130


at Ludiq.FullSerializer.fsReflectedConverter.TryDeserialize
(Ludiq.FullSerializer.fsData data, System.Object& instance,
System.Type storageType) [0x000b3] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\Converters\fsReflectedConverter.cs:105


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_5_Converter
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type resultType, System.Object& result) [0x0001a] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:899


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_4_Cycles
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type resultType, System.Object& result) [0x00032] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:889


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_3_Inheritance
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type storageType, System.Object& result,
System.Collections.Generic.List`1[Ludiq.FullSerializer.fsObjectProcessor]&
processors) [0x0015c] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:864


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_2_Version
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type storageType, System.Object& result,
System.Collections.Generic.List`1[Ludiq.FullSerializer.fsObjectProcessor]&
processors) [0x0011c] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:768


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_1_CycleReference
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type storageType, System.Object& result,
System.Collections.Generic.List`1[Ludiq.FullSerializer.fsObjectProcessor]&
processors) [0x00049] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:713


at Ludiq.FullSerializer.fsSerializer.TryDeserialize
(Ludiq.FullSerializer.fsData data, System.Type storageType, System.Type
overrideConverterType, System.Object& result) [0x0003d] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:666


at Ludiq.FullSerializer.fsReflectedConverter.TryDeserialize
(Ludiq.FullSerializer.fsData data, System.Object& instance,
System.Type storageType) [0x00082] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\Converters\fsReflectedConverter.cs:97


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_5_Converter
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type resultType, System.Object& result) [0x0001a] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:899


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_4_Cycles
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type resultType, System.Object& result) [0x00032] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:889


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_3_Inheritance
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type storageType, System.Object& result,
System.Collections.Generic.List`1[Ludiq.FullSerializer.fsObjectProcessor]&
processors) [0x0015c] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:864


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_2_Version
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type storageType, System.Object& result,
System.Collections.Generic.List`1[Ludiq.FullSerializer.fsObjectProcessor]&
processors) [0x0011c] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:768


at
Ludiq.FullSerializer.fsSerializer.InternalDeserialize_1_CycleReference
(System.Type overrideConverterType, Ludiq.FullSerializer.fsData data,
System.Type storageType, System.Object& result,
System.Collections.Generic.List`1[Ludiq.FullSerializer.fsObjectProcessor]&
processors) [0x00049] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:713


at Ludiq.FullSerializer.fsSerializer.TryDeserialize
(Ludiq.FullSerializer.fsData data, System.Type storageType, System.Type
overrideConverterType, System.Object& result) [0x0003d] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Dependencies\FullSerializer\fsSerializer.cs:666


at Ludiq.Serialization.DeserializeJson
(Ludiq.FullSerializer.fsSerializer serializer, System.String json,
System.Object& instance, System.Boolean forceReflected) [0x00015] in

C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Serialization\Serialization.cs:171


at Ludiq.Serialization.DeserializeInto
(Ludiq.SerializationData data, System.Object& instance,
System.Boolean forceReflected) [0x0002e] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Serialization\Serialization.cs:113


--- End of inner exception stack trace ---

at
Ludiq.Serialization.DeserializeInto (Ludiq.SerializationData data,
System.Object& instance, System.Boolean forceReflected) [0x0007f] in

C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Serialization\Serialization.cs:127


at
Ludiq.LudiqBehaviour.UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize
() [0x00010] in
C:\Users\lazlo\Projects\Bolt1\Package\Ludiq.Core\Runtime\Unity\LudiqBehaviour.cs:46

UnityEngine.Debug:LogError(Object, Object)
Ludiq.LudiqBehaviour:UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize()
(at
C:/Users/lazlo/Projects/Bolt1/Package/Ludiq.Core/Runtime/Unity/LudiqBehaviour.cs:52)


Bolt Version:
1.4.3f2
Unity Version:
2019.1.4f1
.NET Version:
4.5

Duplicates 1

Under Review

Hi Omzy,

Thanks for the report. I must admit I didn't test reserialization during play mode. I'll do some tests and make sure that it doesn't cause any error.

+1
Under Review

Hi Pawel,

Thanks for the report. If I understand correctly, this happens because scripts get reloaded while already in play mode, right?

For example, if you attach the debugger before entering playmode, you wouldn't get the issue?

Working on Fix

Hi Pawel,

Thanks for the report. Fixing the underlying issue to maintain data integrity after a live assembly reload would be too complex for the time being. Starting in v.1.4.4, Bolt will instead block assembly reloads in Play Mode. If your Unity preferences are set to support it, a warning will be shown to let the user know what's happening.

Because you can always attach the debugger before entering play mode, I think this hotfix is sufficient for now; it will at least prevent any kind of data corruption.