It looks like you're new here. If you want to get involved, click one of these buttons!
Zizanyman            
            
                Member             
            for i, val in pairs(self.balls) do if val:getY() > 500 then self.world:destroyBody(val.body) end end  | 
Comments
[-] Liasoft
http://docs.giderosmobile.com/reference/physics/b2World/destroyBody#b2.World:destroyBody
So another solution if you are not going to need the object anymore is:
[-] Liasoft
It's good you have found your own solution, but just out of curiosity is using your own script or, are you using Box2dEasy or any? If you are using your own script, how are you definied running the world (EnterFrame)? for future references.
[-] Liasoft
Could you perhaps write a short, complete project which illustrates the problem and gives the error.
In Nebula Retro, I do the same thing: destroy crates when they fall off the screen (ie I destroy both the Sprite and the body), I didn't get an error, see here for how I did it:
https://github.com/john-blackburn/nebularetro/blob/master/main.lua#L1079
This function is called on ENTER_FRAME as well.
The .body field has been set up earlier (manually by me, it is not a standard Sprite field)
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Likes: antix, john26
[-] Liasoft
This is the way (IMHO) to work with tables of game objects.. pairs is slow.
[-] Liasoft