OrcaSlicer icon indicating copy to clipboard operation
OrcaSlicer copied to clipboard

Malformed temp file paths in Windows cause post-process scripts to fail

Open unklegwar opened this issue 3 months ago • 3 comments

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

  1. 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)

  2. Add script to post-processing

  3. Slice

  4. Attempt to PRINT or SAVE AS GCODE file.

  5. See error similar to mine, with mangled temp path.

Actual results

Image

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

unklegwar avatar Aug 26 '26 06:08 unklegwar

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

creat3dworld avatar Nov 14 '26 05:11 creat3dworld

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?

  1. 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.
  2. 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.
  3. 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.

gushanji avatar Nov 24 '26 10:11 gushanji

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:

  1. 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.

  2. 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.pp to .gcode and got the identical failure. The .pp suffix makes no difference.

  3. 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.)

creat3dworld avatar Nov 27 '26 00:11 creat3dworld