Skip to content

Commit c3ae6aa

Browse files
authored
Merge pull request #106454 from KoBeWi/new_cryptic_error_to_your_collection
Fix potential crash when checking unsaved history
2 parents b7b3a1a + 1d3ade9 commit c3ae6aa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

editor/editor_undo_redo_manager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,20 @@ void EditorUndoRedoManager::set_history_as_saved(int p_id) {
377377

378378
void EditorUndoRedoManager::set_history_as_unsaved(int p_id) {
379379
History &history = get_or_create_history(p_id);
380-
history.saved_version = -1;
380+
history.saved_version = 0;
381381
}
382382

383383
bool EditorUndoRedoManager::is_history_unsaved(int p_id) {
384384
History &history = get_or_create_history(p_id);
385+
if (history.saved_version == 0) {
386+
return true;
387+
}
385388

386389
int version_difference = history.undo_redo->get_version() - history.saved_version;
387390
if (version_difference > 0) {
388391
List<Action>::Element *E = history.undo_stack.back();
389392
for (int i = 0; i < version_difference; i++) {
393+
ERR_FAIL_NULL_V_MSG(E, false, "Inconsistent undo history.");
390394
if (E->get().mark_unsaved) {
391395
return true;
392396
}
@@ -395,6 +399,7 @@ bool EditorUndoRedoManager::is_history_unsaved(int p_id) {
395399
} else if (version_difference < 0) {
396400
List<Action>::Element *E = history.redo_stack.back();
397401
for (int i = 0; i > version_difference; i--) {
402+
ERR_FAIL_NULL_V_MSG(E, false, "Inconsistent redo history.");
398403
if (E->get().mark_unsaved) {
399404
return true;
400405
}

0 commit comments

Comments
 (0)