Malformed temp file paths in Windows cause post-process scripts to fail
Is there an existing issue for this problem?
- [x] I have searched the existing issues
Snapmaker_Orca Version
2.3.5
Operating System (OS)
Windows
OS Version
Windows 10 Pro
Additional system information
Path building mixes back slashes and forward slashes, creating a mess that Windows/Python chokes on.
Post-processing script "C:\Users\Eric\AppData\Local\Python\bin\python.exe" "F:\Bricklayers-main\bricklayers_my.py" on file C:\Users\Eric\AppData\Local\Temp/snapmaker_orca_model/Tue_Aug_25/23_25_58#31824#3047/M etadata.31824.10.gcode.pp failed. Error code: 1
Note how the Temp file path starts with backslashes, switches to forward slashes, then reverts to one last backslash at the very end.
This works correctly in vanilla Orcaslicer, and has for well over a year.
Printer
Snapmaker U1
How to reproduce
-
Make a basic python post processing script that accepts a path from the slicer (go use the Bricklayers script from github, for a quick one)
-
Add script to post-processing
-
Slice
-
Attempt to PRINT or SAVE AS GCODE file.
-
See error similar to mine, with mangled temp path.
Actual results
Expected results
Proper formation of path to temp file, and successful processing of gcode, which is then uploaded or saved.
Project file & Debug log uploads
This is not project specific
Checklist of files to include
- [ ] Log file
- [ ] Project file
Anything else?
No response
Root cause confirmed: Model::get_backup_path() built the temp path by string concatenation with a hardcoded /, so on Windows (C:\Users\...\Temp) the result mixes backslashes and forward slashes — exactly the path in your report. That path becomes the temp G-code path handed to the post-process script, and Windows/Python chokes on it.
Fix: build the path with boost::filesystem::path operators, which insert the native separator. The directory layout is unchanged.
PR: https://github.com/Snapmaker/OrcaSlicer/pull/1203
Thanks — and thanks for pasting the full path. We walked the code along your path; here is what we can confirm, plus three things that would let us pin down which change actually fixes it.
Confirmed:
- The temp directory really is built by string concatenation: Model::get_backup_path() (Model.cpp:1111-1125) adds temporary_dir() to a hard-coded "/snapmaker_orca_model/" (:1120) and "%a_%b_%d/%H_%M_%S#" (:1121), so on Windows you necessarily get the mixed form C:...\Temp/snapmaker_orca_model/... . After that, Model.cpp:1168 appends another "/", PartPlate.cpp:3435 appends the filename with operator/=, and PostProcessor.cpp:251 appends ".pp" — which matches your screenshot segment by segment.
- That path is passed to the post-processing script unquoted: PostProcessor.cpp:35 only quotes an argument when it contains a space, tab, newline or double quote, and your path contains none, so it goes into the command line bare.
What we still can't tell:
We tested a path of the same mixed shape locally (C:...\Temp/xxx.txt) and both the Windows file
API and .NET/Python open() handle it fine — so mixed separators alone may not be what makes the
script exit 1. A more suspicious detail: exporting/saving G-code first copies the file and appends
".pp" (BackgroundSlicingProcess.cpp:800, make_copy=true), so the script receives a filename like
.31824.10.gcode.pp — dot-prefixed, and the extension is .pp rather than .gcode.
So could you check three things?
- Does it fail only on SAVE AS / export, or also when you hit PRINT directly? Uploading takes a different branch (BackgroundSlicingProcess.cpp:929, make_copy=false, filename still ends in .gcode). If only saving fails, the ".pp" suffix is the likelier culprit rather than separators.
- Does your script (Bricklayers) check the input file's extension or name? If it has an endswith('.gcode') style check, ".gcode.pp" would not match.
- Could you paste the script's own error output? Right now we only have "Error code: 1", which doesn't show the Python-side exception. Running it manually and copying stderr is enough: "C:\Users\Eric\AppData\Local\Python\bin\python.exe" "F:\Bricklayers-main\bricklayers_my.py" "<full path to that .pp file>"
One more note: we do have PR #1203 that rebuilds the path with boost::filesystem::path operators, so the mixed separators go away. But I'd rather confirm from the above that it targets your actual failure, instead of changing one thing and missing the root cause.
Thanks for walking the code, @gushanji. I reproduced it and ran the script manually on the captured file — here are the three things you asked for:
-
Export or Print? I tested G-code export (Save As). Slice succeeded, export failed with Error code: 1 and the same mixed temp path. I did not run the Print branch, since that would start a real print. But the failure is in the script reading the file content, not in which branch hands it the file, so I would expect the same failure on Print for the same content.
-
Does Bricklayers check the extension or name? No. I checked the source — there is no extension or name check at all. The test backs it up: I ran the script on a byte-identical copy renamed from
.gcode.ppto.gcodeand got the identical failure. The.ppsuffix makes no difference. -
The script's own error: running it manually gives:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 4115
at bricklayers.py line 46, infile.readlines(). The file is opened with no encoding, so Python on Windows defaults to cp1252 while the G-code contains a UTF-8 byte.
So the failure is the script's text-mode read of the file content, not the mixed separators — PR #1203 would not fix this one. The fix belongs in the script: open(..., encoding='utf-8').
Reproduced on 3d1PC: Snapmaker Orca 2.4.1, Python 3.11.9, OrcaCube_v2.3mf, U1, 0.4 mm nozzle. (Testing and diagnosis were done by Muse, my AI assistant, under my direction.)