Fix insert key crash with no animation

This commit is contained in:
Samuele Panzeri 2023-04-24 12:46:07 +02:00
parent 248e5245e4
commit 4067907074

View File

@ -527,7 +527,8 @@ Object *CanvasItemEditor::_get_editor_data(Object *p_what) {
} }
void CanvasItemEditor::_keying_changed() { void CanvasItemEditor::_keying_changed() {
if (AnimationPlayerEditor::get_singleton()->get_track_editor()->is_visible_in_tree()) { AnimationTrackEditor *te = AnimationPlayerEditor::get_singleton()->get_track_editor();
if (te && te->is_visible_in_tree() && te->get_current_animation().is_valid()) {
animation_hb->show(); animation_hb->show();
} else { } else {
animation_hb->hide(); animation_hb->hide();
@ -3948,6 +3949,7 @@ void CanvasItemEditor::_notification(int p_what) {
select_sb->set_content_margin_all(4); select_sb->set_content_margin_all(4);
AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("visibility_changed", callable_mp(this, &CanvasItemEditor::_keying_changed)); AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("visibility_changed", callable_mp(this, &CanvasItemEditor::_keying_changed));
AnimationPlayerEditor::get_singleton()->connect("animation_selected", callable_mp(this, &CanvasItemEditor::_keying_changed).unbind(1));
_keying_changed(); _keying_changed();
_update_editor_settings(); _update_editor_settings();
} break; } break;
@ -4135,6 +4137,8 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation,
const HashMap<Node *, Object *> &selection = editor_selection->get_selection(); const HashMap<Node *, Object *> &selection = editor_selection->get_selection();
AnimationTrackEditor *te = AnimationPlayerEditor::get_singleton()->get_track_editor(); AnimationTrackEditor *te = AnimationPlayerEditor::get_singleton()->get_track_editor();
ERR_FAIL_COND_MSG(!te->get_current_animation().is_valid(), "Cannot insert animation key. No animation selected.");
te->make_insert_queue(); te->make_insert_queue();
for (const KeyValue<Node *, Object *> &E : selection) { for (const KeyValue<Node *, Object *> &E : selection) {
CanvasItem *ci = Object::cast_to<CanvasItem>(E.key); CanvasItem *ci = Object::cast_to<CanvasItem>(E.key);