Fixture Destroy 0.8.0

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.
Post Reply
acp0112
Prole
Posts: 4
Joined: Tue Jan 17, 2012 10:16 pm

Fixture Destroy 0.8.0

Post by acp0112 »

Creating a fixture and then immediately destroying it seems to cause love to crash during the subsequent call to World:update.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Fixture Destroy 0.8.0

Post by Boolsheet »

I don't see it crashing with something simple like this.

Code: Select all

local step = 1 / 60
W = love.physics.newWorld(0, 1000)

W:update(step)

B = love.physics.newBody(W, 400, 0, "dynamic")
S = love.physics.newCircleShape(10)
F = love.physics.newFixture(B, S, 1)

W:update(step)
W:update(step)
W:update(step)

B2 = love.physics.newBody(W, 400, 0, "dynamic")
S2 = love.physics.newCircleShape(10)
F2 = love.physics.newFixture(B2, S2, 1)

F2:destroy()

W:update(step)

B2:destroy()

W:update(step)
W:update(step)

W:destroy()
Do you create the Fixture in a callback? Box2D assumes that you do not alter the physics world during the timestep and may throw (currently uncaught) exceptions or crash horribly. Adding new bodies and fixtures should be done after the timestep. The destruction of objects is queued by LÖVE as a convenience, but I recommend to do it after the timestep as well because it might make debugging more difficult.
Shallow indentations.
acp0112
Prole
Posts: 4
Joined: Tue Jan 17, 2012 10:16 pm

Re: Fixture Destroy 0.8.0

Post by acp0112 »

thanks for the response. i probably should have stated that i am using coroutines. i have included an example.

Code: Select all

function love.load()
  w = love.physics.newWorld(0, 1000)
end

function love.update(dt)
  b = love.physics.newBody(w, 400, 0, "dynamic")
  s = love.physics.newCircleShape(10)
  co = coroutine.create(function()
    while true do
      f = love.physics.newFixture(b, s, 1)
      f:setFilterData(1,65535,-1)
      coroutine.yield()
    end
  end)
  coroutine.resume(co)
  coroutine.resume(co)

  f:destroy()

  w:update(dt)
end
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Fixture Destroy 0.8.0

Post by Boolsheet »

Aha. It's not the coroutines, but an actual bug in Box2D. setFilterData will refilter the contacts and the destroy call doesn't remove all proxies properly. I don't think you can do anything about it from the Lua side.
Shallow indentations.
acp0112
Prole
Posts: 4
Joined: Tue Jan 17, 2012 10:16 pm

Re: Fixture Destroy 0.8.0

Post by acp0112 »

you are correct it is not the coroutine. well thanks for the help.
Post Reply

Who is online

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