How to debug crashes in the garbage collector

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.
MaartenDM
Prole
Posts: 3
Joined: Sat Aug 23, 2014 11:00 am

How to debug crashes in the garbage collector

Post by MaartenDM »

Hi Lövers!

I'm developing a rather large Löve game and am hitting an elusive crash. After playing fine for 30 minutes+, an occasional crash occurs. I can reproduce this in the Visual Studio debugger using the 0.9.1 source code. runtime.cpp :

Image

Object is invalid here, with its _vfptr 0xfeeefeee indicating freed memory, which causes the release() call to fail.

However, this does not give me more info than 'the garbage collector is trying to release an invalid - probably previously released - object'.

Does anyone have any pointers how to debug that? [Efficiently I mean, not 'comment out one system at a time and see if it still happens' - it takes 40+ mins to see if it reproduces (without any guarantees), and the codebase is large]. Or how eg double releases can be detected?
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to debug crashes in the garbage collector

Post by slime »

Does your lua code use love threads? The reference counting code for LÖVE's objects is unfortunately not thread-safe right now, which I guess might cause an issue like that in some circumstances when threads are used.

Can you figure out what type the object causing the crash is (maybe through the 'flags' field of the Proxy object in w__gc)?
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: How to debug crashes in the garbage collector

Post by Jasoco »

The only times I've had Löve crash because of the garbage collector is when I am doing 3D. (Or if I force stop the collector to debug) And it's because I'm creating a lot of garbage in a short amount of time. Too much for the collector to clean up. Usually tweaking the settings using collectgarbage() will help but when there's a lot of garbage, there'll be a lot of lag while it cleans it up. These days I keep an eye on my garbage amount by printing collectgarbage("count")/1024 somewhere on the screen (Bottom right corner) and can tell when something I've changed is leaking a lot.

Try printing onto the screen while running the game and watch if the number gets really high.
Last edited by Jasoco on Tue Jan 13, 2015 6:52 pm, edited 1 time in total.
MaartenDM
Prole
Posts: 3
Joined: Sat Aug 23, 2014 11:00 am

Re: How to debug crashes in the garbage collector

Post by MaartenDM »

Ah, I didn't know of the use of flags, thanks!

flags 1, 2 and 18 are set - that makes it image data I think.

And yes, we do use threads - for resource loading and AI mostly.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: How to debug crashes in the garbage collector

Post by kikito »

Are you creating lots of images in rapid succession? Maybe you are running out of memory.
When I write def I mean function.
MaartenDM
Prole
Posts: 3
Joined: Sat Aug 23, 2014 11:00 am

Re: How to debug crashes in the garbage collector

Post by MaartenDM »

There are places where we do create lots of images in rapid succession ( before each round ), but that does not seem to be cause of increasing memory. Even if it would, could running out of memory explain a crash like above?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to debug crashes in the garbage collector

Post by Robin »

Could you upload a .love?

Creating lots of images is usually a big no-no.
Help us help you: attach a .love.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: How to debug crashes in the garbage collector

Post by Fenrir »

Are you using meshes? Currently there's a memory leak with mesh management in Löve 0.9.1, see this post:
viewtopic.php?f=4&t=78209#p169886
It made my game to crash too when loading/reloading too many times levels.
Muris
Party member
Posts: 131
Joined: Fri May 23, 2014 9:18 am

Re: How to debug crashes in the garbage collector

Post by Muris »

Jasoco wrote: These days I keep an eye on my garbage amount by printing collectgarbage("count")/1024 somewhere on the screen (Bottom right corner) and can tell when something I've changed is leaking a lot.

Try printing onto the screen while running the game and watch if the number gets really high.
Sorry for asking this on someones elses topic, but this got me curious.

How much is a lot? I am assuming the value is in megabytes after dividing by 1024, and on my game it keeps hopping between 0.6 and 1.5 which doesnt sound that much. It keeps getting cleaned up on my game maybe roughly every 2 seconds from 1.5 to 0.6.

I tried stacking up one npc with a lot of items, and it uses not so optimized algorithm to count a value for a movement (strategy rpg), and the garbage collector consumption jumped from 1 to 30 during the calculation while the game froze for a second or two.
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to debug crashes in the garbage collector

Post by slime »

kikito wrote:Are you creating lots of images in rapid succession? Maybe you are running out of memory.
Fenrir wrote:Are you using meshes? Currently there's a memory leak with mesh management in Löve 0.9.1
The crash report isn't from a memory allocation issue – it's almost definitely a race condition related to LÖVE's reference-counted objects.

I'll see if I can get it fixed for 0.9.x, and if so I'll get you to test an updated build of LÖVE.


EDIT: Here's the latest version of LÖVE 0.9.2 with a fix for you to try: http://love2d.org/builds
Last edited by slime on Thu Jan 15, 2015 5:23 am, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests