Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

animation curves crash

Discussion in 'Scripting' started by xCeas, Jul 13, 2021.

  1. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Hey guys!

    I'm having a ROUGH time with animation curves.
    When I use evaluate, they cause the editor to crash (although they are indeed defined).
    Here is the stack trace:
    Code (CSharp):
    1.  
    2.  
    3. Stack Trace of Crashed Thread 23608:
    4. 0x00007FF6EDD4C097 (Unity) DynamicHeapAllocator::Allocate
    5. 0x00007FF6EDD4287A (Unity) DualThreadAllocator<DynamicHeapAllocator>::Allocate
    6. 0x00007FF6EDD2A73A (Unity) MemoryManager::Allocate
    7. 0x00007FF6EDD30DF4 (Unity) MemoryManager::Reallocate
    8. 0x00007FF6EDD3FB98 (Unity) realloc_internal
    9. 0x00007FF6EC025434 (Unity) dynamic_array_detail::dynamic_array_data::reallocate
    10. 0x00007FF6EE95E956 (Unity) dynamic_array_detail::dynamic_array_data::resize_buffer
    11. 0x00007FF6EBF74A38 (Unity) dynamic_array<KeyframeTpl<float>,0>::resize_buffer_nocheck
    12. 0x00007FF6EBF742AD (Unity) dynamic_array<KeyframeTpl<float>,0>::assign
    13. 0x00007FF6EEC0B42B (Unity) TransferField_NonArray<StreamedBinaryWrite,Converter_SimpleNativeClass<AnimationCurveTpl<float> > >
    14. 0x00007FF6EEC2D784 (Unity) Transfer_SimpleNativeClass<StreamedBinaryWrite,AnimationCurveTpl<float>,0>
    15. 0x00007FF6EC0741FB (Unity) ExecuteSerializationCommands<ConfigSettingsRead>
    16. 0x00007FF6EEC2C840 (Unity) Transfer_ManagedObject<StreamedBinaryRead,0>
    17. 0x00007FF6EC0741FB (Unity) ExecuteSerializationCommands<ConfigSettingsRead>
    18. 0x00007FF6EEC2C840 (Unity) Transfer_ManagedObject<StreamedBinaryRead,0>
    19. 0x00007FF6EC0741FB (Unity) ExecuteSerializationCommands<ConfigSettingsRead>
    20. 0x00007FF6EEC14365 (Unity) StreamedBinaryWrite::TransferSTLStyleArray<ArrayOfManagedObjectsTransferer>
    21. 0x00007FF6EEC2C90A (Unity) Transfer_ManagedObject<StreamedBinaryWrite,1>
    22. 0x00007FF6EEC0917C (Unity) TransferField_LinearCollection<ReportScriptingObjectsTransfer>
    23. 0x00007FF6ED216826 (Unity) ExecuteSerializationCommands<SafeBinaryRead>
    24. 0x00007FF6ED222427 (Unity) TransferScriptingObject<StreamedBinaryWrite,0>
    25. 0x00007FF6ED21ED69 (Unity) SerializableManagedRefTransfer::Transfer<SerializableManagedRefBackupGenerator>
    26. 0x00007FF6ED2AE745 (Unity) WriteObjectToVector
    Does anyone have any idea why would it cause the editor to outright crash?

    I can share my code if needed.

    Thanks in advance,
    Itay
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    If you comment out the evaluate in your current code, does it crash?

    It might be you have a corrupted curve. Does it work if you "clear" it or set it to one of the default presets?

    What if you make a new scene, with an AnimationCurve and call evaluate on it? Does it crash? What about in a new project? etc.
     
  3. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Here is the evaluate usage:
    Code (CSharp):
    1.    try
    2.                     {
    3.  
    4.                         existingResultEntity.AddGraphStatResult(graphStatResultIndex,                      entity.graphOverride.Modifier.Evaluate(ratio));
    5.                     }
    6.                     catch (Exception e)
    7.                     {
    8.                         Debug.LogError(e);
    9.                     }
    And this is how I create an entity which's curve will be evaluated with some other modifiers:
    Code (CSharp):
    1.  
    2.                                 modifiedStatEntity.AddGraphStat(new AnimationCurve(new Keyframe[0]));
    Code (CSharp):
    1.  
    2.  
    3. Stack Trace of Crashed Thread 14716:
    4. 0x00007FF6F03EBB9E (Unity) memcpy
    5. 0x00007FF6EEC0B42B (Unity) TransferField_NonArray<StreamedBinaryWrite,Converter_SimpleNativeClass<AnimationCurveTpl<float> > >
    6. 0x00007FF6EEC2D784 (Unity) Transfer_SimpleNativeClass<StreamedBinaryWrite,AnimationCurveTpl<float>,0>
    7. 0x00007FF6EC0741FB (Unity) ExecuteSerializationCommands<ConfigSettingsRead>
    8. 0x00007FF6EEC2C840 (Unity) Transfer_ManagedObject<StreamedBinaryRead,0>
    9. 0x00007FF6EC0741FB (Unity) ExecuteSerializationCommands<ConfigSettingsRead>
    Sometimes it also fails on Serialization.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Right now there's no way to tell what is failing or why with that code.

    You gotta strip that stuff apart:

    - only call evaluate, do nothing with the result

    - don't call evaluate, hard-wire a value into your addgraphstat thingy

    etc.
     
  5. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    So I managed to isolate the case a bit.
    It occurs upon serializing an AnimationCurve - I'm using unity 2019.4f

    Basically what I did:
    - Play
    - Stop
    NO CRASH
    - Play
    - Instantiate an object with an animation curve
    - Stop
    CRASH
     
  6. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    After a few more hours of constant debugging and even upgrading unity version, I'm growing more suspicious this is related to AnimationCurve serialization issues.
    Did anyone else tackle such a behavior?
    (Not sure if that's related, though I also use Odin Inspector, and the class which contains this AnimationCurve is serializable).

    The bug reproduces if I do the following:
    0. Play
    1. Instantiate an object with AnimationCurve (which is a valid constant)
    2. Stop Play
    3. Go through inspectors which present the AnimationCurve
    4. Play Again
    5. Crash

    If step 1 is skipped, the crash would not occur.

    Here are some more relevant logs from the crash:
    Code (CSharp):
    1.  
    2. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF6E80EF31A)
    3. 0x00007FF6E80EF31A (Unity) (function-name not available)
    4. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF6E90A2586)
    5. 0x00007FF6E90A2586 (Unity) (function-name not available)
    6. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF6E99EE596)
    7. 0x00007FF6E99EE596 (Unity) (function-name not available)
    8. 0x0000029182F461FE (UnityEngine.CoreModule) UnityEngine.AnimationCurve.Internal_Destroy()
    9. 0x0000029182F45CBB (UnityEngine.CoreModule) UnityEngine.AnimationCurve.Finalize()
    10. 0x0000029185ED7E4C (mscorlib) System.Object.runtime_invoke_virtual_void__this__()
    11. 0x00007FFFAA194279 (mono-2.0-bdwgc) mono_gc_reference_queue_new
    If any moderator could reply to this issue I'd really appreciate it, it had been blocking me from progressing roughly about a week.

    Thanks.
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Can you repro in a blank project with just Odin and your extra serializable class?

    If so, file a bug ...
     
    Bunny83 likes this.
  8. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Sure I will update tomorrow
     
    Bunny83 likes this.
  9. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    I imported some parts of my code (the models that contain the AnimationCurve, an asset example (one the models is a scriptable object) and the custom editor) into a blank project of unity 2019.4f

    I can't seem to replicate the issue there, but that maybe because I'm missing the actual trigger which causes this issue in the first place.
    The error does seem to originate due to an issue with AnimationCurve Serialization - I tried implementing ISerializationCallbackReceiver interface on the crashing object, and even an empty OnBeforeSerialize, caused the editor to crash.

    Here is the error log that occurred, without said interface:
    Code (CSharp):
    1. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF6920370A0)
    2. 0x00007FF6920370A0 (Unity) (function-name not available)
    3. 0x0000019AF7912C33 (UnityEngine.CoreModule) UnityEngine.AnimationCurve.GetKeys()
    4. 0x0000019AF7912A2B (UnityEngine.CoreModule) UnityEngine.AnimationCurve.get_keys()
    5. 0x0000019AFF284D83 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.AnimationCurveAtomHandler.CopyImplementation()
    6. 0x0000019AFF2849F2 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.BaseAtomHandler`1.Copy()
    7. 0x0000019AFF0F03B3 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.PropertyValueEntry`2.UpdateValues()
    8. 0x0000019AFF03F1E1 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.PropertyValueEntry.Update()
    9. 0x0000019AFF03E853 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.UpdateValueEntry()
    10. 0x0000019AFF03CD93 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.Update()
    11. 0x0000019AFF0A11EB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    12. 0x0000019AFF0A13CB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    13. 0x0000019AFF0A13CB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    14. 0x0000019AFF0A13CB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    15. 0x0000019AFF0A13CB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    16. 0x0000019AFF0A13CB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    17. 0x0000019AFF0A13CB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.InspectorProperty.OnStateUpdate()
    18. 0x0000019AFF08F473 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.PropertyTree.BeginDraw()
    19. 0x0000019AFF08EB6B (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.PropertyTree.Draw()
    20. 0x0000019AFF08EAAB (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinEditor.DrawTree()
    21. 0x0000019AFF00E664 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinEditor.DrawOdinInspector()
    22. 0x0000019AFF00E013 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinEditor.OnInspectorGUI()
    23. 0x0000019AFF00D9DC (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinEditorWindow.DrawEditor()
    24. 0x0000019AFF00D575 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinEditorWindow.DrawEditors()
    25. 0x0000019AFEFFF2C1 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinEditorWindow.OnGUI()
    26. 0x0000019AFEFDB943 (Sirenix.OdinInspector.Editor) Sirenix.OdinInspector.Editor.OdinMenuEditorWindow.OnGUI()
    27. 0x0000019ACAB24274 (UnityEditor) UnityEditor.HostView.InvokeOnGUI()
    28. 0x0000019ACAB23C03 (UnityEditor) UnityEditor.DockArea.DrawView()
    I was thinking maybe it is related to the ScriptableObject instance - but that wouldn't explain why it worked just fine in the blank project (which also uses serialization).
     
  10. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    I've made various debugging sessions and come to realize that the source of the issue can reproduce if the project is ran twice, assuming that in the first run an object with an AnimationCurve is instantiated (it is also marked as DontDestroyOnLoad).

    As I previously stated I failed to reproduce this issue in a separate project (could be caused by me missing what causes the corruption in the 1st place).

    In any case - it is definitely related to AnimationCurve, and to Serialization (if I mark said object as [NonSerialized] the issue would not reproduce).
     
  11. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Solved the issue - it was indeed a corrupted reference which was hidden off my eyes.