Fix crash on New Project after opening the Design tab (#16997)

# Description

Starting a new project or opening one could crash OrcaSlicer if the
Design tab had been opened earlier in the session and OrcaSlicer wasn't
the active window at that moment. It no longer crashes, and the Design
tab is still cleared for the new project as before.

Only reachable with the CAD feature turned on. No change to slicing or
to project files.

# Screenshots/Recordings/Graphs

<!--
> Please attach relevant screenshots to showcase the UI changes.
> Please attach images that can help explain the changes.
-->

## Tests

Reproduced on a Windows Release build of a feature branch that has the
same code, by driving New Project with OrcaSlicer visible but not the
active window and a debugger attached. Before the change it crashed with
the same stack as the original crash log. After it, the same steps
finish without a crash. This branch (main plus the change) wasn't built
on its own. There's no automated test, because the crash needs a real
change of window focus.

<!--
> A guide for users on how to download the artifacts from this PR.
-->

[How to Download Pull Requests Artifacts for
Testing](https://www.orcaslicer.com/wiki/how_to_download_pr_artifacts)
This commit is contained in:
SoftFever authored and GitHub committed 2026-10-29 14:03:19 +08:00
commit 0db324476f
1 file changed
+11 -7
+11 -7
View File
@@ -10906,13 +10906,6 @@ void Plater::priv::reset(bool apply_presets_change, bool reload_presets)
// clear_objects() only drops the ModelObjects; the CAD recipe is Model-level state and would
// otherwise be written into every project saved for the rest of the session.
model.cad_recipe.clear();
#ifdef SLIC3R_CAD
// Same reason, one level up: the Design tab keeps the editable document, not the Model, so
// clearing the recipe alone leaves the tab showing the previous project's feature tree —
// and its next edit syncs that tree straight back into the new project.
if (DesignPanel* design = DesignPanel::if_built())
design->clear_document();
#endif
assemble_view->get_canvas3d()->reset_explosion_ratio();
update();
@@ -10923,6 +10916,17 @@ void Plater::priv::reset(bool apply_presets_change, bool reload_presets)
object_list_changed();
}
#ifdef SLIC3R_CAD
// Same reason as the recipe, one level up: the Design tab keeps the editable document, not
// the Model, so clearing the recipe alone leaves the tab showing the previous project's
// feature tree — and its next edit syncs that tree straight back into the new project.
// It runs only once the scene is rebuilt: clearing hands the keyboard to the Design canvas,
// and when the app has no focus that activates the main window, whose 3D view repaints on
// the spot. Before update() that repaint picks against the plates reinit() deleted.
if (DesignPanel* design = DesignPanel::if_built())
design->clear_document();
#endif
project.reset();
wxGetApp().sidebar().printer_combox()->clear_selected_dev_id();