From 808f4e8cb9be502060317526f887b1d31cbeb40a Mon Sep 17 00:00:00 2001 From: kobewi Date: Mon, 5 Feb 2024 17:42:37 +0100 Subject: [PATCH] Check if history exists before discarding --- editor/editor_data.cpp | 4 +++- editor/editor_undo_redo_manager.cpp | 4 ++++ editor/editor_undo_redo_manager.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 786e841c21c0..b4cf6d8de1e6 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -649,7 +649,9 @@ void EditorData::remove_scene(int p_idx) { EditorNode::get_singleton()->emit_signal("scene_closed", edited_scene[p_idx].path); } - undo_redo_manager->discard_history(edited_scene[p_idx].history_id); + if (undo_redo_manager->has_history(edited_scene[p_idx].history_id)) { // Might not exist if scene failed to load. + undo_redo_manager->discard_history(edited_scene[p_idx].history_id); + } edited_scene.remove_at(p_idx); } diff --git a/editor/editor_undo_redo_manager.cpp b/editor/editor_undo_redo_manager.cpp index c2491f861138..94f76dbc4195 100644 --- a/editor/editor_undo_redo_manager.cpp +++ b/editor/editor_undo_redo_manager.cpp @@ -375,6 +375,10 @@ bool EditorUndoRedoManager::has_redo() { return false; } +bool EditorUndoRedoManager::has_history(int p_idx) const { + return history_map.has(p_idx); +} + void EditorUndoRedoManager::clear_history(bool p_increase_version, int p_idx) { if (p_idx != INVALID_HISTORY) { History &history = get_or_create_history(p_idx); diff --git a/editor/editor_undo_redo_manager.h b/editor/editor_undo_redo_manager.h index effa36a87c48..e8c782871cb8 100644 --- a/editor/editor_undo_redo_manager.h +++ b/editor/editor_undo_redo_manager.h @@ -130,6 +130,7 @@ class EditorUndoRedoManager : public Object { bool is_history_unsaved(int p_idx); bool has_undo(); bool has_redo(); + bool has_history(int p_idx) const; String get_current_action_name(); int get_current_action_history_id();