Browse Source

Merge pull request #16724 from xsellier/bugfix/clear-make-godot-crash

Bugfix: Godot engine crashes due to _clear function
Rémi Verschelde 7 years ago
parent
commit
0d50aa8468
1 changed files with 19 additions and 16 deletions
  1. 19 16
      scene/gui/text_edit.cpp

+ 19 - 16
scene/gui/text_edit.cpp

@@ -3204,24 +3204,27 @@ String TextEdit::get_line(int line) const {
 void TextEdit::_clear() {
 
 	if (undo_enabled) {
-		_clear_redo();
 		String undo_text = get_text();
 
-		/* UNDO!! */
-		TextOperation op;
-		op.type = TextOperation::TYPE_CLEAR;
-		op.from_line = 0;
-		op.from_column = 0;
-		op.to_line = MAX(0, get_line_count() - 1);
-		op.to_column = get_line(op.to_line).length();
-		op.text = undo_text;
-		op.version = ++version;
-		op.chain_forward = false;
-		op.chain_backward = false;
-
-		op.prev_version = get_version();
-		_push_current_op();
-		current_op = op;
+		if (undo_text.length() > 0) {
+			_clear_redo();
+
+			/* UNDO!! */
+			TextOperation op;
+			op.type = TextOperation::TYPE_CLEAR;
+			op.from_line = 0;
+			op.from_column = 0;
+			op.to_line = MAX(0, get_line_count() - 1);
+			op.to_column = get_line(op.to_line).length();
+			op.text = undo_text;
+			op.version = ++version;
+			op.chain_forward = false;
+			op.chain_backward = false;
+
+			op.prev_version = get_version();
+			_push_current_op();
+			current_op = op;
+		}
 	} else {
 		clear_undo_history();
 	}