love.js web game crash page refresh emscripten

Discuss any ports of LÖVE to different platforms.
Post Reply
HappySoft
Prole
Posts: 1
Joined: Tue Feb 01, 2022 9:43 pm

love.js web game crash page refresh emscripten

Post by HappySoft »

hi guys,

Apart from a some html and c# within Unity and recently getting into lua i don't really have a programming background.
But i finagled my way to porting my love2d game to a browser game through a udemy course and Tanner's love.js

well i'm trying to figure out how to resolve this: game plays fine but when i refresh the page i get a
"Assertion failed: emscripten_set_main_loop: there can only be one main loop function at once:" error
and the game freezes.. ill provide a screenshot. (ran with python 2 localHTTP)

so i figured.. the main loop should just cancel and restart when the the page gets refreshed right?
something in the love.js file must be tweaked.. but i have no clue how or where exactly.

does anyone have any experience with this issue? or any idea what i should learn to be able to solve an issue like this?


kind regards, Michiel
Attachments
crash error after page refresh
crash error after page refresh
help.png (201.06 KiB) Viewed 34719 times
User avatar
alexjgriffith
Prole
Posts: 30
Joined: Wed Jan 20, 2021 9:50 pm

Re: love.js web game crash page refresh emscripten

Post by alexjgriffith »

It would depend on how you setup the build. It looks like it only soft reloaded the page, and the game state was somehow cached and its throwing an error because there can only be one main loop. I've never seen this before.

I'd recommend checking out Davidobot's fork of love.js https://github.com/Davidobot/love.js . He's updated it to support love11.3 and its super straight forward to get working for most games.
User avatar
alexjgriffith
Prole
Posts: 30
Joined: Wed Jan 20, 2021 9:50 pm

Re: love.js web game crash page refresh emscripten

Post by alexjgriffith »

I did some digging and found that this error arises when you try to call Love() in JS after its already been called. What are you using to wrap the game?
josephpayne
Prole
Posts: 2
Joined: Tue Nov 14, 2023 8:57 am

Re: love.js web game crash page refresh emscripten

Post by josephpayne »

Hello,

The error message you're seeing is from Emscripten, the tool that is used to compile Love2D (and many other things) to JavaScript so it can run in a web browser. What it's saying is that you're trying to set up a new game loop while an old one is still running.

When you refresh the page, your browser tries to clean up everything from the previous page load, but it looks like the game loop from Love2D isn't being cleaned up properly. This could be because of some issue in love.js or it could be something specific to your game code.

One thing you could try is to manually stop the game loop before refreshing the page. You could do this with some JavaScript code that listens for the beforeunload event, which is fired just before the page is unloaded. Here's a simple example:

Code: Select all

window.addEventListener('beforeunload', function() {
  // This is where you would add code to stop the game loop
  // The exact code depends on how your game loop is implemented
});
You would need to replace the comment with code that actually stops the game loop. The exact code would depend on how your game loop is implemented. It might involve calling a function like love.event.quit() or setting a variable that your game loop checks to see if it should continue running.

If you're not sure how to stop the game loop, you might want to ask for help on the Love2D forums or on a site like Stack Overflow. Be sure to include more information about how your game loop is set up and what you've tried so far.

Hope this helps!
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests