Nested icon indicating copy to clipboard operation
Nested copied to clipboard

Infinite loop in _renderGrid

Open chlirre opened this issue 12 years ago • 7 comments

I was able to make both Chrome and Safari freeze.

Steps to reproduce

  • Change box.className = 'box size' + Math.ceil( Math.random()*3 ) + Math.ceil( Math.random()*3 ); to box.className = 'box size' + Math.ceil( Math.random()*15 ) + Math.ceil( Math.random()*15 ); in makeboxes.js
  • Append or prepend some boxes until you get some big ones.
  • Make the browser window really narrow.

_renderGrid seems to loop

I'm guessing one of the for-loops within the while(true){} never breaks.

Maybe I shouldn't make that big boxes?

But there should be some nice fallback, right?

chlirre avatar Jan 30 '13 21:01 chlirre

I was able to reproduce the issue as well, by simply making my browser window fairly narrow (approximately the size of a smartphone in landscape orientation). I didn't make any changes to the code to increase the size of the boxes as nested generates them, although I see where this can be accomplished in _setBoxes(). I was also able to trace the source of the infinite loop as the while loop in _renderGrid().

james-pykl avatar Feb 11 '13 15:02 james-pykl

Looks like the condition that creates the infinite loop occurs when the viewport is reduced to less than the size of the widest element in the grid.

james-pykl avatar Feb 11 '13 17:02 james-pykl

This seems to occur when this.columns and col in _renderGrid() are equal. It effectively prevents for (var column = 0; column < (this.columns - col); column++) { from running and results in an infinite loop.

I've fixed this locally by adding the following code before the while(true) loop

if(this.columns === col) {
    this.columns++;
}

thedaian avatar Feb 12 '13 17:02 thedaian

This sorts out another issue where if minWidth was larger than 242px I would get the same infinite loop / break.

MetaHeavies avatar Aug 15 '14 07:08 MetaHeavies

This issue has 4 duplicates in #17 #30 #44 #48. This really needs to be fixed already! Can someone fix and do a pull request? If the dev is MIA, maybe do a fork?

eablokker avatar Sep 18 '14 21:09 eablokker

Started using https://github.com/metafizzy/packery as an alternative

MetaHeavies avatar Sep 19 '14 07:09 MetaHeavies

Try as explained here. https://github.com/suprb/Nested/issues/48 This works for me.

testuserlove avatar Jan 16 '15 18:01 testuserlove