[Solved] Physics - shapes get destroyed when collected
Posted: Wed Aug 10, 2011 12:10 am
Hi there ![Smile :)](./images/smilies/ms-smile.png)
I'm making a pong-like game that uses love.physics, and I've been getting some weird behavior. I've found out what was the cause and fixed it, but I still don't know whether this was a bug in Löve or was like that by design. That's how I encountered it:
I surrounded the playing field with invisible walls at the borders of the screen, and discarded references to shapes, because I didn't need to do anything with them later. I put a ball inside and set it bouncing around. I did some test runs, and each time, after some 2-3 minutes, the ball kept falling out of screen (like it was passing through walls). It happened even when the ball was going really slow, so it ruled out tunneling. After some time of wondering what may be causing this, I've found out. The walls were disappearing when Lua garbage-collected the shapes. When I explicitly ran garbage collector after creating walls, they were gone.
Now, is this the intended behavior? Should I always keep somewhere references to shapes I create? I initially thought that since shapes are always attached to a body (that itself is "attached" to world), it's not necessary to keep references to them.
![Smile :)](./images/smilies/ms-smile.png)
I'm making a pong-like game that uses love.physics, and I've been getting some weird behavior. I've found out what was the cause and fixed it, but I still don't know whether this was a bug in Löve or was like that by design. That's how I encountered it:
I surrounded the playing field with invisible walls at the borders of the screen, and discarded references to shapes, because I didn't need to do anything with them later. I put a ball inside and set it bouncing around. I did some test runs, and each time, after some 2-3 minutes, the ball kept falling out of screen (like it was passing through walls). It happened even when the ball was going really slow, so it ruled out tunneling. After some time of wondering what may be causing this, I've found out. The walls were disappearing when Lua garbage-collected the shapes. When I explicitly ran garbage collector after creating walls, they were gone.
Now, is this the intended behavior? Should I always keep somewhere references to shapes I create? I initially thought that since shapes are always attached to a body (that itself is "attached" to world), it's not necessary to keep references to them.