Page 1 of 1

Unusual crashing within the first few seconds of the game with no error message.

Posted: Mon Mar 04, 2024 2:30 pm
by DTmg
I'm making a 2d survival game with randomly generated terrain (I swear I've never played terraria but that is besides the point) and I am running into a rather unusual issue: within the first few seconds of the game launching, more often than not it will freeze for a couple seconds and then close unexpectedly without an error message. Right before it closes it appears to resume again for a few more frames, so I honestly have no idea what is happening. I've looked around the forums already and can't seem to find a solution, the closest I've come is viewtopic.php?p=248403&hilit=freeze+pairs+jit#p248403, but I'm using the latest version of Löve2D (11.5 as of writing) which should include LuaJIT 2.1, and even if it was pairs() acting up I don't believe I'm changing the table while I'm looping through it (any time I spawn a new object I queue it to be added after the frame ends). My code is kind of a mess, so sorry in advance, but I have attached my .love file. If anyone has any idea what is causing this, please let me know, because I am having a hard time debugging this. Thanks in advance!

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Mon Mar 04, 2024 5:10 pm
by slime
I haven't looked too thoroughly but I noticed in base.lua and world.lua you're making a bunch of new quads every frame and immediately throwing them away - the garbage collector might not be able to keep up when it's done every frame like that (since Lua's garbage collector doesn't know the full amount of memory used by love objects). I imagine it's impacting performance as well.

Usually you'd just make quads once during loading and reuse those.

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Mon Mar 04, 2024 6:04 pm
by DTmg
Nice catch, I forgot that newQuad actually creates a new löve object. I've gone ahead and changed that (and it seems to be noticeably performing a bit better overall, so thanks!). However I keep running into the same issue, and I can't seem to pinpoint what might be causing it. It only happens at the very start of the game, I've not had it crash on me in the middle of playing yet. I can't seem to replicate it with the JIT off, and the fact that there is no error message when this happens makes it difficult to debug.

I went ahead and attached the version that doesn't spam quads, thanks for catching that! :)

If anyone else can figure out why it might be crashing seemingly at random, please let me know. It's been causing me quite the headache for the past few days.

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Mon Mar 04, 2024 7:08 pm
by BrotSagtMist
There seems to be no way to reproduce that problem for me.
How often does it actually happen?

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Mon Mar 04, 2024 8:41 pm
by DTmg
It happens on average maybe 1/5th of the times I open the game, so it's not a one-off. It's been happening for the past few days, so I figured I would ask here since I'm having trouble debugging it.

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Mon Mar 04, 2024 10:12 pm
by slime
Which operating system are you using? If you're on Linux and you've installed love from a package manager instead of the AppImage download on the home page, then love will be using whatever patch version of LuaJIT that the package manager provides instead of a version that's guaranteed to have the pairs fixes.

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Tue Mar 05, 2024 3:02 pm
by DTmg
I am using windows 10, and I downloaded the 32-bit version of Löve2D 11.5, however I have not been able to reproduce the crash for a good while now on either version (the fixed quads version and the misused quads version). I'm trying to figure out how to consistently reproduce it, but it seems to happen completely at random.

Re: Unusual crashing within the first few seconds of the game with no error message.

Posted: Tue Mar 05, 2024 6:59 pm
by Bobble68
Sounds kind of similar to an issue I was getting a while back - never found a fix for it, though I know it happened when the game was started from the main menu instead.