### 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 (items.write[p_idx].dirty) {
		items.write[p_idx].text_buf->clear();
		Ref<Font> font = items[p_idx].separator ? theme_cache.font_separator : theme_cache.font;
		int font_size = items[p_idx].separator ? theme_cache.font_separator_size : theme_cache.font_size;
		if (items[p_idx].text_direction == Control::TEXT_DIRECTION_INHERITED) {
			items.write[p_idx].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
		} else {
			items.write[p_idx].text_buf->set_direction((TextServer::Direction)items[p_idx].text_direction);
		}
		items.write[p_idx].text_buf->add_string(items.write[p_idx].xl_text, font, font_size, items[p_idx].language);
		items.write[p_idx].accel_text_buf->clear();
		items.write[p_idx].accel_text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
		items.write[p_idx].accel_text_buf->add_string(_get_accel_text(items.write[p_idx]), font, font_size);
		items.write[p_idx].dirty = false;
	}
}
void PopupMenu::_menu_changed() {