ClementSparrow / Pattern-Script

Open Source HTML5 Game Engine based on PuzzleScript
20 stars 2 forks source link

Uncaught ReferenceError: redraw is not defined #63

Closed david-pfx closed 1 year ago

david-pfx commented 1 year ago

The error is this:

Uncaught ReferenceError: redraw is not defined
    at Image.<anonymous> (font.js:32:2)

It doesn't happen all the time, and I'm not sure what triggers it. The cause seems to be that you've added a redraw() call to font.js, but that's in graphic.js which is not loaded by the browser until much later. I'm not an expert on browser file loading, but the general idea seems to be that if the browser loads all the files then these functions get hoisted and the order no longer matters. This is during development, so perhaps an error in an intervening file blocks the loading of graphic.js and triggers the error.

Once it happens, it's sticky. The only way I found to make it go away is to clear the browser cache. Very annoying.

I'll try shuffling a few files around, see if that helps. I think the real solution is not to rely on the browser, use ES5 require.

ClementSparrow commented 1 year ago

Yes the problem is that redraw is called when the font is loaded, which sometimes happens before graphics.js is loaded and parsed. Especially if the files are in the browser cache. But graphics.js needs the font. Usual chicken and egg problem. I will fix that the clean way :-)

david-pfx commented 1 year ago

Glad I asked. I was tearing my hair for a while. Makes sense in the bigger picture.