the things i've done with physics:
create bodies/shapes
set category/masks
use persist contact callbacks
destroy bodies(bodies, not shapes) when missile dies(2 seconds)
you can hold left key to shoot around, wsad to move, press right key for temporary boost. after play around a bit, the game would eventually crash and gives me the following pop-up error message.
need help:randomly crashes caused by physics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
need help:randomly crashes caused by physics
- Attachments
-
- game.love
- (1.32 MiB) Downloaded 167 times
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: need help:randomly crashes caused by physics
This happens when you destroy a body/shape when it is still colliding.
Re: need help:randomly crashes caused by physics
When you destroy a body all of its associated shapes are destroyed as well.titangate wrote:destroy bodies(bodies, not shapes)
Re: need help:randomly crashes caused by physics
thanks for your help, but i'd like to ask for more help
so i'm currently thinking, when trying to delete, mark the body/shape as 'needed to delete', when receive remove collision callback on those shapes and there're no more shapes colliding with them, push them into a table and delete them afterwards. sounds quite troublesome, is there any replacement or this is an OK approach?
so i'm currently thinking, when trying to delete, mark the body/shape as 'needed to delete', when receive remove collision callback on those shapes and there're no more shapes colliding with them, push them into a table and delete them afterwards. sounds quite troublesome, is there any replacement or this is an OK approach?
Re: need help:randomly crashes caused by physics
Finite state machines. When a body needs to be deleted you change its state to 'destroyed'. After processing the collisions and updating the b2world, you update the states of your bodies. Naturally, the 'destroyed' state will delete its owner body. Behavior trees are another approach that can also be used for AI and animation.titangate wrote:thanks for your help, but i'd like to ask for more help
so i'm currently thinking, when trying to delete, mark the body/shape as 'needed to delete', when receive remove collision callback on those shapes and there're no more shapes colliding with them, push them into a table and delete them afterwards. sounds quite troublesome, is there any replacement or this is an OK approach?
Last edited by ivan on Sun Jul 03, 2011 3:17 pm, edited 1 time in total.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: need help:randomly crashes caused by physics
Right, you probably want to mark it for deletion and set it to not collide with anything, then you can remove it the next frame.
See Shape:setMask.
See Shape:setMask.
Re: need help:randomly crashes caused by physics
emm. sorry to bother, but i implemented as i described but the crash continued on.
i'm pasting the related code:
and when i'm trying to delete the bodies, i did as follows:
self.shape:setMask(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
map:destroyBody(self)
map:removeUnit(self)
thanks for your patience and time. please help me to find what's wrong with these steps :/ i'm getting kind of frustrated..
i'm pasting the related code:
Code: Select all
function Map:destroyBody(obj)
self.destroys[obj] = true
end
function Map:update(dt)
for k,v in pairs(self.destroys) do
self.destroys[k] = true
end
collides = {}
self.world:update(dt)
handlepersist()
for k,v in pairs(self.destroys) do
if v then
k.shape:destroy()
k.body:destroy()
self.destroys[k] = nil
end
end
for unit,v in pairs(self.units) do
if unit.update then unit:update(dt) end
end
end
function handlepersist()
for k,v in ipairs(collides) do
local a,b,c=unpack(v)
if a and map.destroys[a] then map.destroys[a] = false end
if b and map.destroys[b] then map.destroys[b] = false end
if map.units[a] and map.units[b] then
if a.persist then
a:persist(b,c)
end
if b.persist then
b:persist(a,c)
end
end
end
end
-- Collision callback that got registered
function persist(a,b,coll)
table.insert(collides,{a,b,coll})
end
self.shape:setMask(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
map:destroyBody(self)
map:removeUnit(self)
thanks for your patience and time. please help me to find what's wrong with these steps :/ i'm getting kind of frustrated..
Last edited by bartbes on Sun Jul 03, 2011 5:39 pm, edited 1 time in total.
Reason: Code tag
Reason: Code tag
Re: need help:randomly crashes caused by physics
ok.. i found this way that potentially solved my problem
k.body:setPosition(-200000,-200000)
just toss the body far away. so far i've encountered no crashes, although i know this method is super awkward.
k.body:setPosition(-200000,-200000)
just toss the body far away. so far i've encountered no crashes, although i know this method is super awkward.
Re: need help:randomly crashes caused by physics
THANKS GUYS! i missed this. this should do the same as toss it away, and i tried, everything is functioning now.bartbes wrote:Right, you probably want to mark it for deletion and set it to not collide with anything, then you can remove it the next frame.
See Shape:setMask.
I can keep on working now!
i've almost given up lol.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: need help:randomly crashes caused by physics
Just to put this out there, this is a bad solution because it will put everything at the same place. Only change one of the x-y coords if you're going to do this.titangate wrote:ok.. i found this way that potentially solved my problem
k.body:setPosition(-200000,-200000)
just toss the body far away. so far i've encountered no crashes, although i know this method is super awkward.
Kurosuke needs beta testers
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Nikki and 6 guests