### Godot version

4.0.2

### System information

Windows 11

### Issue description

Changing node type from PopupMenu to ItemList causes Godot to crash

### Steps to reproduce

Change node type from PopupMenu to ItemList

### Minimal reproduction project

n/a
if (p_idx < 0) {
		p_idx += get_item_count();
	}
	ERR_FAIL_INDEX(p_idx, items.size());
	if (items[p_idx].submenu == p_submenu) {
		return;
	}
	items.write[p_idx].submenu = p_submenu;
	control->queue_redraw();
	child_controls_changed();
	_menu_changed();
}
void PopupMenu::toggle_item_checked(int p_idx) {
	ERR_FAIL_INDEX(p_idx, items.size());
	items.write[p_idx].checked = !items[p_idx].checked;
	control->queue_redraw();
	child_controls_changed();
	_menu_changed();
}
String PopupMenu::get_item_text(int p_idx) const {
	ERR_FAIL_INDEX_V(p_idx, items.size(), "");
	return items[p_idx].text;
}
Control::TextDirection PopupMenu::get_item_text_direction(int p_idx) const {