soimy / maxrects-packer

A max rectangle 2d bin packer npm-module for packing glyphs or images into multiple sprite-sheet/atlas

Home Page:https://soimy.github.io/maxrects-packer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infinite recrusion when using addArray of oversized rect with non-exclusive tag matching

tionkje opened this issue · comments

When adding a rect that oversizes the exclusively tagged bin using addArray, It hangs and after some time crashes with RangeError: Maximum call stack size exceeded

const opt = { smart: true, pot: false, square: false, allowRotation: false, 
    tag: true,
    exclusiveTag: false
}         
const packer = new MaxRectsPacker(1024, 1024, 0, opt)
let input = [
    {width: 2000, height: 1000, data: { tag: 'bla' }} 
];
packer.addArray(input); // Never returns / RangeError: Maximum call stack size exceeded

The same happens when the sum of the rects ends up oversized

let input = [
    {width: 1000, height: 1000, data: { number:1, tag: 'bla' }},
    {width: 1000, height: 1000, data: { number:2, tag: 'bla' }} 
];
packer.addArray(input); // Never returns / RangeError: Maximum call stack size exceeded

No big issue, just annoying when trying to reduce the size of the output bins.

Otherwise great stuff 👍

@tionkje Take a look now with this new version to see if it solves your issue!

Yes this fixed my test case. Thanks!

I did notice that a single over sized rect seems to just disappear? I think it normally creates a bin with an oversized flag.