### 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
control->queue_redraw();
				}
				for (int i = 0; i < items.size(); i++) {
					if (items[i].submenu.is_empty()) {
						continue;
					}
					Node *n = get_node(items[i].submenu);
					if (!n) {
						continue;
					}
					PopupMenu *pm = Object::cast_to<PopupMenu>(n);
					if (!pm || !pm->is_visible()) {
						continue;
					}
					pm->hide();
				}
				set_process_internal(false);
			} else {
				if (!is_embedded()) {
					set_process_internal(true);
				}
				
				margin_container->add_theme_constant_override("margin_left", theme_cache.panel_style->get_margin(Side::SIDE_LEFT));
				margin_container->add_theme_constant_override("margin_top", theme_cache.panel_style->get_margin(Side::SIDE_TOP));
				margin_container->add_theme_constant_override("margin_right", theme_cache.panel_style->get_margin(Side::SIDE_RIGHT));
				margin_container->add_theme_constant_override("margin_bottom", theme_cache.panel_style->get_margin(Side::SIDE_BOTTOM));
			}
		} break;
	}
}