GraphemeNFT / rarible-scaffold

MIT License
0 stars 0 forks source link

entropy.shift() crashes #33

Closed dcsan closed 3 years ago

dcsan commented 3 years ago

on "YourCollectibles" page

Unhandled Rejection (TypeError): Cannot read property 'shift' of undefined
(anonymous function)
src/helpers/grapheme.js:85
  82 | 
  83 | // returns a function that will return randomness on each call. recycle for limitless fun.
  84 | function makeRng(entropy) {
> 85 |   return () => { const x = entropy.shift(); entropy.push(x); return x; }
  86 | }
  87 | 
  88 | function renderLetter(grid, rng) {
View compiled
dcsan commented 3 years ago

added code to prevent this crashing, but not sure why - last one seems to always get called with an empty 'entropy' value. i don't see how tho, as the calling function always provides a _rnd unless it's called from somewhere else.

// returns a function that will return randomness on each call. recycle for limitless fun.
function makeRng (entropy) {
  if (!entropy) {
    console.warn('makeRng but no entropy', entropy);
    entropy = [4, 4, 1, 4, 1, 7, 0, 4, 0, 3, 2]
  }
  return () => { const x = entropy.shift(); entropy.push(x); return x; }
}
tomosaigon commented 3 years ago

It will crash if you call it with empty data. But if you try to do that, it shouldn't render anything, that's invalid or undefined.