love.event.quit("restart") crashes when threads running

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

love.event.quit("restart") crashes when threads running

Post by Luke100000 »

Hello,
When I try to restart my game via love.event.quit("restart") and there is at least one running thread, the game will exit with following message: Error: [string "boot.lua"]:230: Already initialized
How can I avoid this? Do I have to take care, that every thread is closed when trying to restart?
I am using love 0.10.2.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.event.quit("restart") crashes when threads running

Post by slime »

love is not able to forcefully kill threads (partly because attempting to do so could cause a complete hang if a mutex lock was active, and it would also cause memory leaks).

It's up to your own code to make sure a thread ends properly when love quits. The love.quit callback is a good place to send messages through channels to indicate that threads should exit, and then Thread:wait should be called after the messages are sent (and you'll need code inside the thread to make it finish running when it receives a certain message, of course).
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: love.event.quit("restart") crashes when threads running

Post by raidho36 »

Haha slime beat me to it.

You need to kill and/or join your threads manually.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love.event.quit("restart") crashes when threads running

Post by zorg »

(And before any confusion arises, raidho probably means by "join" what slime said above, Thread:wait, to be precise.)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: love.event.quit("restart") crashes when threads running

Post by Luke100000 »

Thanks for the quick replies!
I will try out this solution.
zorg wrote: Sun May 21, 2017 10:24 pm (And before any confusion arises, raidho probably means by "join" what slime said above, Thread:wait, to be precise.)
I actually was confused :awesome:
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: love.event.quit("restart") crashes when threads running

Post by raidho36 »

Join threads is the standard terminology for this action. LÖVE arbitrarily renames a lot of things, just to confuse people.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.event.quit("restart") crashes when threads running

Post by slime »

raidho36 wrote: Mon May 22, 2017 10:43 am Join threads is the standard terminology for this action. LÖVE arbitrarily renames a lot of things, just to confuse people.
Thread:wait() calls SDL_WaitThread under the hood. SDL_WaitThread calls WaitForSingleObjectEx or pthread_join depending on the OS.
Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests