Make the CLI able to slice: fix the version check and two null GUI crashes - #839
Open
KuzuriAo wants to merge 2 commits into
Open
Make the CLI able to slice: fix the version check and two null GUI crashes#839KuzuriAo wants to merge 2 commits into
KuzuriAo wants to merge 2 commits into
Conversation
The CLI compares a loaded file's version against SLIC3R_VERSION, which is a legacy constant inherited from BambuStudio (01.10.01.50 in common_func.hpp) and does not track the product version (Snapmaker_VERSION, 2.3.6). Since real project files report major version 2 and the constant reports major 1, the major versions never matched and every file was rejected with Version Check: File Version 2.3.0.6 not supported by current cli version 01.10.01.50 including files saved by Snapmaker Orca itself. The comparison was also wrong in the other direction: "cli_ver.maj() != file_version.maj() || cli_ver.min() < file_version.min()" rejects files older than the application as well as newer ones, and evaluates the minor version across differing major versions. Match upstream OrcaSlicer (src/OrcaSlicer.cpp), which compares against its product version and only rejects files newer than the application. Also report the product version in the error message rather than the legacy constant.
PartPlate reaches wxGetApp() on the headless path in two places. wxGetApp()
dereferences the wx application object, which does not exist in CLI mode, so
slicing from the command line dies with SIGSEGV before producing output.
1) PartPlate::generate_plate_name_texture() calls wxGetApp().em_unit() to
scale the plate name font:
stop reason = EXC_BAD_ACCESS (code=1, address=0x398)
frame #0: Slic3r::GUI::GUI_App::em_unit(this=0x0000000000000000) const
at GUI_App.hpp:517
Upstream OrcaSlicer guards this function by returning early when there is
no 3D canvas, since there is nothing to generate a texture for in that
case. Do the same, additionally null checking m_partplate_list and
m_plater before dereferencing them: the CLI path reaches this function
with a null Plater, so fetching the canvas directly would crash inside the
guard itself. The canvas is then reused later in the function instead of
being fetched a second time, which also matches upstream.
2) expand_plate_extruders() calls wxGetApp().filaments_cnt() and
wxGetApp().preset_bundle to expand virtual extruder ids for mixed
filaments, and is reached from PartPlate::get_extruders():
stop reason = EXC_BAD_ACCESS (code=1, address=0x868)
frame #0: Slic3r::GUI::GUI_App::filaments_cnt(this=0x0000000000000000)
const at GUI_App.cpp:6832
Return early when there is no application object. There is no GUI preset
bundle to expand ids against in CLI mode, so they are left as they are,
which is what happened before mixed filament support was added. This code
has no upstream counterpart.
Both guards only trigger when running headless, so the GUI is unaffected:
there is always a 3D canvas and an application object with a window open.
Author
|
Thanks again for picking this one up. Two more small macOS fixes went in tonight, both tested, in case they are useful to batch with this: #852 — a model opened from Space is loaded and then discarded during startup. macOS delivers the URL after launch rather than in argv, so switch_to_3d never gets set and post_init starts a blank project over it. No rush on either, and happy to split or rework them if you would rather they were shaped differently. |
|
@KuzuriAo Thanks, I will check it soon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make the CLI able to slice: fix the version check and two null GUI crashes
As shipped,
Snapmaker_Orcaon the command line cannot slice anything. Every file is rejected on a version check, and if you get past that with--allow-newer-filethe process segfaults. That rules out any scripted or server side use of the slicer.There are three independent defects: one in the version check, and two places where GUI-only code is reached headless. The first two are fixed by matching what upstream OrcaSlicer already does. The third is in code that only exists in this fork.
Defect 1: the version check rejects every project file
src/Snapmaker_Orca.cppcompares the loaded file's version againstSLIC3R_VERSION. That is a legacy constant inherited from BambuStudio, defined insrc/common_func/common_func.hppas01.10.01.50, and it does not track the product version, which sits right next to it asSnapmaker_VERSION "2.3.6". Real project files report major version 2, the constant reports major 1, so the major versions never match and everything is refused:That file was saved by Snapmaker Orca itself, so the CLI cannot even read its own output.
The comparison has a second problem.
cli_ver.maj() != file_version.maj() || cli_ver.min() < file_version.min()rejects files older than the application as well as newer ones, and evaluates the minor version even when the major versions differ.Upstream OrcaSlicer (
src/OrcaSlicer.cpp) compares against its product version and only rejects files that are genuinely newer:This PR adopts exactly that, using
Snapmaker_VERSION, and reports the product version in the error message instead of the legacy constant.Defect 2: null GUI application in CLI mode
With the version check passed, the process dies immediately:
PartPlate::generate_plate_name_texture()callswxGetApp().em_unit()to scale the plate name font. Headless there is no application object, so it dereferences null.Upstream guards the same function by returning early when there is no 3D canvas, since without one there is no texture to generate. This PR does the same, with one addition: the CLI path here reaches the function with a null
Plater, so the guard null checksm_partplate_listandm_platerbefore fetching the canvas. Fetching it directly, as upstream does, crashes inside the guard itself. Upstream uses this same defensive form elsewhere in the file.The canvas is then reused later in the function rather than being fetched a second time, which also matches upstream.
Defect 3: null GUI application in expand_plate_extruders()
With both of the above fixed, a plain single filament project still crashed:
expand_plate_extruders()insrc/slic3r/GUI/PartPlate.cppcallswxGetApp().filaments_cnt()andwxGetApp().preset_bundleto expand virtual extruder ids for mixed filaments. It is called fromPartPlate::get_extruders(), which the CLI always reaches. Unlike the first two defects this code has no upstream counterpart, it came in with mixed filament support.This PR returns early when there is no application object. In CLI mode there is no GUI preset bundle to expand ids against, so they are left as they are, which is what happened before mixed filament support existed. The GUI path is unchanged, since
wxTheAppis always present there.Testing
Built from
main, macOS Apple Silicon. Compared against the released Snapmaker Orca 2.3.6, which reports the same version, so the only difference is these commits.The test file is a cone exported from Snapmaker Orca's own GUI: single filament, one plate, by layer, default settings, 35 KB. Its embedded version is
2.3.6, the same as the application reading it. It is attached to this PR.Each case below runs the identical command with a fresh datadir, so nothing carries between runs:
TestSlice.3mf.zip
Released 2.3.6, as a user would run it
Released 2.3.6, with the version check bypassed via
--allow-newer-fileThis case matters: it shows the crashes are separate defects and not a consequence of the version check.
This branch, as a user would run it
Also checked on this branch, since the crashes were reached by different code paths:
--allow-newer-file, since its application tag claims a newer version): exit 0, 35 MB outputThe GUI is unaffected.
generate_plate_name_texture()only returns early when there is no 3D canvas, andexpand_plate_extruders()only when there is no application object, neither of which happens with a window open. The version check is not on the GUI load path.Why this matters
The immediate motivation is a publishing pipeline: converted project files need to be sliced headlessly so that print time and filament usage can be shown alongside them. Any automated workflow, batch conversion, regression testing, or server side slicing needs a working CLI. Right now upstream OrcaSlicer's CLI has to be used instead, which means not using the Snapmaker profiles and G-code the fork exists to provide.
One small note for anyone reproducing:
--allow-newer-fileis a bare boolean. Passing a value, as in--allow-newer-file 1, makes the1be parsed as an input filename and fails withNo such file: 1.