vexe / VFW

MIT License
492 stars 67 forks source link

CycleReference Error #65

Closed geff closed 9 years ago

geff commented 9 years ago

Hi,

I have this error each time I start my game in editor :

Error deserializing member `MonsterAdds` (List`1) in `MonsterData` Error message: "Object reference not set to an instance of an object" Stacktrace:   at FullSerializer.fsMetaType.get_HasDefaultConstructor () [0x0008d] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\Reflection\fsMetaType.cs:244 
  at FullSerializer.fsMetaType.CreateInstance () [0x00081] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\Reflection\fsMetaType.cs:279 
  at FullSerializer.Internal.fsReflectedConverter.CreateInstance (FullSerializer.fsData data, System.Type storageType) [0x00007] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\Converters\fsReflectedConverter.cs:73 
  at FullSerializer.fsSerializer.InternalDeserialize_3_Inheritance (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x000d7] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:683 
  at FullSerializer.fsSerializer.InternalDeserialize_2_Version (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x000da] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:642 
  at FullSerializer.fsSerializer.InternalDeserialize_1_CycleReference (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x0003a] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:611 
  at FullSerializer.fsSerializer.TryDeserialize (FullSerializer.fsData data, System.Type storageType, System.Object& result) [0x0003f] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:586 
  at FullSerializer.Internal.fsReflectedConverter.TryDeserialize (FullSerializer.fsData data, System.Object& instance, System.Type storageType) [0x0006f] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\Converters\fsReflectedConverter.cs:60 
  at FullSerializer.fsSerializer.InternalDeserialize_5_Converter (FullSerializer.fsData data, System.Type resultType, System.Object& result) [0x0001d] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:725 
  at FullSerializer.fsSerializer.InternalDeserialize_4_Cycles (FullSerializer.fsData data, System.Type resultType, System.Object& result) [0x00034] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:717 
  at FullSerializer.fsSerializer.InternalDeserialize_3_Inheritance (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x000f3] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:696 
  at FullSerializer.fsSerializer.InternalDeserialize_2_Version (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x000da] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:642 
  at FullSerializer.fsSerializer.InternalDeserialize_1_CycleReference (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x0003a] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:611 
  at FullSerializer.fsSerializer.TryDeserialize (FullSerializer.fsData data, System.Type storageType, System.Object& result) [0x0003f] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:586 
  at FullSerializer.Internal.fsIEnumerableConverter.TryDeserialize (FullSerializer.fsData data, System.Object& instance_, System.Type storageType) [0x0005a] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\Converters\fsIEnumerableConverter.cs:58 
  at FullSerializer.fsSerializer.InternalDeserialize_5_Converter (FullSerializer.fsData data, System.Type resultType, System.Object& result) [0x0001d] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:725 
  at FullSerializer.fsSerializer.InternalDeserialize_4_Cycles (FullSerializer.fsData data, System.Type resultType, System.Object& result) [0x00034] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:717 
  at FullSerializer.fsSerializer.InternalDeserialize_3_Inheritance (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x000f3] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:696 
  at FullSerializer.fsSerializer.InternalDeserialize_2_Version (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x000da] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:642 
  at FullSerializer.fsSerializer.InternalDeserialize_1_CycleReference (FullSerializer.fsData data, System.Type storageType, System.Object& result, System.Collections.Generic.List`1 processors) [0x0003a] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:611 
  at FullSerializer.fsSerializer.TryDeserialize (FullSerializer.fsData data, System.Type storageType, System.Object& result) [0x0003f] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\Source\fsSerializer.cs:586 
  at Vexe.Runtime.Serialization.FullSerializerBackend.Deserialize (System.Type type, System.String serializedState, System.Object context) [0x00039] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\FullSerializer\FullSerializerBackend.cs:50 
  at Vexe.Runtime.Serialization.SerializerBackend.DeserializeTargetFromData (UnityEngine.Object target, Vexe.Runtime.Serialization.SerializationData data) [0x00048] in D:\Geff\Log\Rogue\Rogue\Assets\Plugins\Vexe\Runtime\Serialization\Serializers\SerializerBackend.cs:74 
UnityEngine.Debug:LogError(Object)
Vexe.Runtime.Serialization.SerializerBackend:DeserializeTargetFromData(Object, SerializationData) (at Assets/Plugins/Vexe/Runtime/Serialization/Serializers/SerializerBackend.cs:80)
Vexe.Runtime.Types.BetterScriptableObject:DeserializeObject() (at Assets/Plugins/Vexe/Runtime/Types/Core/BetterScriptableObject.cs:87)
Vexe.Runtime.Types.BetterScriptableObject:OnAfterDeserialize() (at Assets/Plugins/Vexe/Runtime/Types/Core/BetterScriptableObject.cs:58)

I Have 2 classes :

public class MonsterData : BetterScriptableObject
{
    public string Name;
    public Sprite IconMonster;
    public Sprite PortraitMonster;
    public MonsterLevel Level;

    public AudioClip Hit;
    public List<MonsterStat> Stats;

    public MoveRange Range;
    public MoveRange Move;

    public List<MonsterAdd> MonsterAdds = new List<MonsterAdd>();

    public MonsterData()
    {
    }
}

[Serializable]
public class MonsterAdd
{
    [MinMaxSlider(0, 15)]
    public MinMaxRange Count = new MinMaxRange(1, 1);

    [fSlider(0f, 1f), Default(1f), Comment("Probabilité que le monstre apparaisse (0% à 100%)")]
    public float Probability = 1f;

    [Comment("S'agit il d'un monstre spécifique ou d'un monstre aléatoire?")]
    public bool IsSpecificAdd;

    [VisibleWhen("IsSpecificAdd")]
    public MonsterData MonsterData = null;
    [VisibleWhen("!IsSpecificAdd")]
    public MonsterLevel MonsterLevel;

    public MonsterAdd()
    {
    }

    public override string ToString()
    {
        if (IsSpecificAdd)
        {
            if (MonsterData != null)
                return MonsterData.name;
            else
                return "Monster not defined";
        }
        else
            return MonsterLevel.ToString();
    }
}

There is a circular reference : MonsterData=>Monster Add=>Monster Data

The game is playable but I want to get rid of this error message. Do you have any ideas?

Thanks.

vexe commented 9 years ago

FS should handle cycles well. I used to get weird errors from FS too, don't know how it works from the inside or why it's spitting those errors, I got frustrated and gave up on it. - That's why I said in the long run Unity's serializer is better. Just inherit BaseScriptableObject instead and make sure the rest of your stuff is Serializable. Sorry, lame solution but that's just the best one I found to deal with those annoyances.