Repository: godot
Issue: Delayed crash after Animations with same name are added to the same AnimationLibrary
Labels: bug,needs testing,crash,topic:animation

### Tested versions

reproducible in v4.3.stable.nixpkgs [77dcf97d8]

### System information

Godot v4.3.stable (77dcf97d8) - NixOS #1-NixOS SMP PREEMPT_DYNAMIC Thu Sep 12 09:13:13 UTC 2024 - X11 - Vulkan (Mobile) - integrated Intel(R) Graphics (ADL GT2) - 12th Gen Intel(R) Core(TM) i5-1240P (16 Threads)

### Issue description

Low information core-dump when adding and hacking with Animation objects while making a multiplayer plugin.  

```
================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.3.stable.nixpkgs (77dcf97d82cbfe4e4615475fa52ca03da645dbd8)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6(+0x40620) [0x7ffff7d0d620] (??:0)
[2] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x2cb27a4] (??:0)
[3] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x54229e] (??:0)
[4] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x4324cd1] (??:0)
[5] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x4325390] (??:0)
[6] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x4299b0a] (??:0)
[7] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x7cbce4] (??:0)
[8] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x68753c] (??:0)
[9] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x234258f] (??:0)
[10] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x2a0a4c5] (??:0)
[11] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x429d1f8] (??:0)
[12] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x22cfe18] (??:0)
[13] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x22cfdc4] (??:0)
[14] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x2326fbf] (??:0)
[15] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x42144f] (??:0)
[16] /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6(+0x2a27e) [0x7ffff7cf727e] (??:0)
[17] /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6(__libc_start_main+0x89) [0x7ffff7cf7339] (??:0)
[18] /nix/store/ss26dyx50lsqh5jdzyq621iq6vcdgxk0-godot4-4.3-stable/bin/godot4() [0x43e605] (??:0)
-- END OF BACKTRACE --
================================================================

```

### Steps to reproduce

I was unintentionally adding Animations with the same name to the same AnimationLibrary due to the fact that they were not set as local_to_scene when they had been instantiated in a scene. 

This seems to have created a bad pointer in the system which causes a crash on evaluation of `$AnimationPlayer.current_animation_length` after a delay.


### Minimal reproduction project (MRP)

This is a very minimal project that reproduces the crash immediately

[animationcrash.zip](https://github.com/user-attachments/files/17531789/animationcrash.zip)


```GDScript
extends Node2D

var a1 : Animation
var a2 : Animation
func _ready():
	var alib : AnimationLibrary = $AnimationPlayer.get_animation_library("liblib")

	print(alib, $AnimationPlayer2.get_animation_library("liblib"))

	var at = alib.get_animation("temp")
	a1 = at.duplicate()
	a1.track_insert_key(0, 0.0, Vector2(1,1))
	alib.add_animation("anim1", a1)
	$AnimationPlayer.play("liblib/anim1")
	$AnimationPlayer.pause()

	var at2 = alib.get_animation("temp")
	a2 = at2.duplicate()
	a2.track_insert_key(0, 0.0, Vector2(1,1))
	alib.add_animation("anim1", a2)
	print("Animation list ", alib.get_animation_list())
	prints(a1.length, a2.length, $AnimationPlayer.current_animation_length)
	
	# The Crash happens only on the delayed evaluation of current_animation_length
	await get_tree().create_timer(0.1).timeout
	prints(a1.length, a2.length, $AnimationPlayer.current_animation_length)
```