### Godot version

v4.1.rc2.official [46424488e]

### System information

Godot v4.1.rc2 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.3623) - AMD Ryzen 7 5700G with Radeon Graphics (16 Threads)

### Issue description

When setting the AnimationTree to active, Godot crashes.

### Steps to reproduce

https://github.com/godotengine/godot/assets/46705245/dbe5eb81-1357-43e8-ac80-a4eb97eea9fc

### Minimal reproduction project

[Crash.zip](https://github.com/godotengine/godot/files/11945826/Crash.zip)

ERR_FAIL_COND(states.has(p_name) == false);
	ERR_FAIL_COND(p_node.is_null());
	ERR_FAIL_COND(String(p_name).contains("/"));
	{
		Ref<AnimationNode> node = states[p_name].node;
		if (node.is_valid()) {
			node->disconnect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed));
			node->disconnect("animation_node_renamed", callable_mp(this, &AnimationNodeStateMachine::_animation_node_renamed));
			node->disconnect("animation_node_removed", callable_mp(this, &AnimationNodeStateMachine::_animation_node_removed));
		}
	}
	states[p_name].node = p_node;
	emit_changed();
	emit_signal(SNAME("tree_changed"));
	p_node->connect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed), CONNECT_REFERENCE_COUNTED);
	p_node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeStateMachine::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);
	p_node->connect("animation_node_removed", callable_mp(this, &AnimationNodeStateMachine::_animation_node_removed), CONNECT_REFERENCE_COUNTED);
}
void AnimationNodeStateMachine::set_state_machine_type(StateMachineType p_state_machine_type) {