From f0d1e8b6255c7363e4a36200ec8fc44dfd9f662e Mon Sep 17 00:00:00 2001 From: gminor7 Date: Tue, 14 Apr 2026 16:29:09 -0400 Subject: [PATCH] fix: prevent rect mutation during tag bin probing --- src/maxrects-packer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/maxrects-packer.ts b/src/maxrects-packer.ts index 30e78a9..580e117 100644 --- a/src/maxrects-packer.ts +++ b/src/maxrects-packer.ts @@ -164,7 +164,12 @@ export class MaxRectsPacker { } // still in the same tag group - if (testBin.add(rect) === undefined) { + const testRect = { ...rect, rot:false, data: { ...rect.data } } + if (testBin.add(testRect) === undefined) { + // IMPORTANT: + + // Use a cloned rect for test placement to avoid mutating + + // the original rect (especially `rot`) during bin probing + // add the rects that could fit into the bins already // do addArray() this.sort(rects.slice(currentIdx, i), this.options.logic).forEach(r => bin.add(r));