PuzzleScript
PuzzleScript copied to clipboard
On startup query string may execute before all files loaded, and then crash
The startup code in editor.js
looks like this:
var fileToOpen=getParameterByName("demo");
if (fileToOpen!==null&&fileToOpen.length>0) {
tryLoadFile(fileToOpen);
code.value = "loading...";
} else {
It is possible for the query string to execute and try to load the file before all the JS files are loaded, causing a crash. The solution is simple. https://stackoverflow.com/a/11258137/1105562
window.addEventListener('load', function() {
// your code here
})
I've checked it out and it works.
good catch, thanks. Note to future, bug-fixing self: check you don't need to reduplicate this fix in the player
I was able to reproduce it easily running locally:
http://localhost:8000/src/editor.html?demo=sokoban
It's likely to turn up in other places, so it's going to need some thought where the fix should go. I can't PR that, so over to you!
I looked into this, but I'm having trouble reproducing it. I've tried in private mode, both hosting locally and on puzzlescript.net, force refresh, different browsers. I wonder if there are some tools that might let me slow down the serving of specific files.
@david-pfx Can you remember what browser/operating system (including versions) you were using to produce this behaviour?
( Also: A note to myself to check the ready-state in addition to hooking up the event handler - https://stackoverflow.com/questions/13364613/how-to-know-if-window-load-event-was-fired-already )
I mostly use the .bat file to run locally and (latest) Chrome for testing.
Note to future self: I can consistently reproduce it on Chrome on MacOS, only in the src build (the compiled version compiles everything to a single js file, so won't exhibit this error), by opening up the network tools and turning on bandwidth throttling, but not deactivating the cash, and reloading.