Bug: PES export writes duplicate trailing thread for 2-color designs (3 thread entries instead of 2) #8

Closed
opened 2026-08-27 15:27:44 +00:00 by Mark · 0 comments
Owner

Summary

When a design has N color blocks, the exported PES contains N+1 threads — the last entry is a duplicate of the first color with zero stitches. Verified via pyembroidery round-trip:

threads in file: 3
  [0] #000000  desc=Black
  [1] #FE370F  desc=Vermilion
  [2] #000000  desc=Black

Root cause

app.py:251-264 only updates previous_color after writing a COLOR_CHANGE record. When the color stream returns to the first color or simply ends, no final settlement happens, and pyembroidery infers an extra empty trailing thread.

Suggested fix

After writing all stitch objects, if previous_color is non-None, emit a final dummy COLOR_CHANGE (or END) to settle the thread table. Or de-dup empty trailing threads in the writer.

Reproduction

curl -X POST http://127.0.0.1:8080/v1/export -H "Content-Type: application/json" -d @shakedown_export_req.json --output giants.pes
python3 -c "import pyembroidery; p=pyembroidery.read_pes("giants.pes"); print(len(p.threadlist))"
# 3  (expected: 2)

Severity

MEDIUM — Brother PR10 reads and sews correctly despite the extra thread entry, but the file is non-canonical and may confuse other tools (Wilcom, Embrilliance, conversion pipelines).

## Summary When a design has N color blocks, the exported PES contains N+1 threads — the last entry is a duplicate of the first color with zero stitches. Verified via pyembroidery round-trip: ``` threads in file: 3 [0] #000000 desc=Black [1] #FE370F desc=Vermilion [2] #000000 desc=Black ``` ## Root cause `app.py:251-264` only updates `previous_color` after writing a `COLOR_CHANGE` record. When the color stream returns to the first color or simply ends, no final settlement happens, and pyembroidery infers an extra empty trailing thread. ## Suggested fix After writing all stitch objects, if `previous_color` is non-None, emit a final dummy `COLOR_CHANGE` (or `END`) to settle the thread table. Or de-dup empty trailing threads in the writer. ## Reproduction ```bash curl -X POST http://127.0.0.1:8080/v1/export -H "Content-Type: application/json" -d @shakedown_export_req.json --output giants.pes python3 -c "import pyembroidery; p=pyembroidery.read_pes("giants.pes"); print(len(p.threadlist))" # 3 (expected: 2) ``` ## Severity MEDIUM — Brother PR10 reads and sews correctly despite the extra thread entry, but the file is non-canonical and may confuse other tools (Wilcom, Embrilliance, conversion pipelines).
Mark 2026-08-30 00:16:03 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/easystitch-service#8
No description provided.