### Godot version

v4.1.1-stable_mono_win64

### System information

Windows 11

### Issue description

I removed the node to replace it with another, but when I change the path in the code, the engine crashes for me.

### Steps to reproduce

I did a screen recording as it happens:

https://github.com/godotengine/godot/assets/116289408/b2fd2689-8d82-44e8-8e02-be01674842e1



### Minimal reproduction project

[MixApo.zip](https://github.com/godotengine/godot/files/12208403/MixApo.zip)

const String &line = get_line(p_line);
	
	for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
		const String &open_key = auto_brace_completion_pairs[i].open_key;
		if (p_col - open_key.length() < 0) {
			continue;
		}
		bool is_match = true;
		for (int j = 0; j < open_key.length(); j++) {
			if (line[(p_col - 1) - j] != open_key[(open_key.length() - 1) - j]) {
				is_match = false;
				break;
			}
		}
		if (is_match) {
			return i;
		}
	}
	return -1;
}
int CodeEdit::_get_auto_brace_pair_close_at_pos(int p_line, int p_col) {