increpare / PuzzleScript

Open Source HTML5 Puzzle Game Engine
MIT License
903 stars 159 forks source link

On startup query string may execute before all files loaded, and then crash #970

Closed david-pfx closed 5 months ago

david-pfx commented 1 year ago

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.

increpare commented 1 year ago

good catch, thanks. Note to future, bug-fixing self: check you don't need to reduplicate this fix in the player

david-pfx commented 1 year ago

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!

increpare commented 5 months ago

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 )

david-pfx commented 5 months ago

I mostly use the .bat file to run locally and (latest) Chrome for testing.

increpare commented 5 months ago

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.

Bildschirmfoto 2024-04-27 um 16 16 38