Thanks.Attempt to use destroyed fixture
Issue with simple physics removal test.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Issue with simple physics removal test.
In my game I am trying to have it so I can remove items when a ball touches them. I have issues trying to remove the items. I have attached a small test case and tried implementing an updated-to-0.8.0 (by making shapes->fixtures) version of this: https://love2d.org/wiki/Remove_Workaround. The ball should fall through the block in this test case and destroy the block, yet it crashes and gives an error, which is also what happens in my much bigger game, saying:
- Attachments
-
- PhysicsColTest.love
- (1.78 KiB) Downloaded 99 times
Re: Issue with simple physics removal test.
You should probably make sure the object you're trying to draw actually has a body before you ask it anything about its body. It'll get self conscious and throw an error like that one.
Once you destroy the fixture the body becomes unavailable, and you're trying to draw it by using its body. No biggie. Keep pluggin'
Once you destroy the fixture the body becomes unavailable, and you're trying to draw it by using its body. No biggie. Keep pluggin'
Re: Issue with simple physics removal test.
I have tried your suggestion and changed my draw code to prevent anything from happening if there is no body by checking if any body is nil:
It does not work still unfortunately.
Code: Select all
function love.draw()
love.graphics.setColor(255,0,0)
if ball.body ~= nil then
love.graphics.circle("line", ball.body:getX(), ball.body:getY(), ball.shape:getRadius())
end
love.graphics.setColor(0,255,0)
if block.body ~= nil then
love.graphics.polygon("line", block.body:getWorldPoints(block.shape:getPoints()))
end
end
Re: Issue with simple physics removal test.
you're also not removing it from the toRemove list.
Re: Issue with simple physics removal test.
Ahh, now I can get it to sort of work. It now runs if I change the update function to this:
But for some reason the square doesn't disappear... Replacing fixture:destroy() with fixture:getBody():destroy() also gives an error. Thanks for all your help so far! I'm just not quite getting it.
Code: Select all
function love.update(dt)
world:update(dt)
for _, fixture in ipairs(toRemove) do
fixture:destroy()
end
for i = #toRemove,1,-1 do
table.remove(toRemove,i)
end
end
Re: Issue with simple physics removal test.
Ok, I was able to figure it out by clearing the block table in the "toRemove" loop, destroying the body and not the fixture, and checking if block.body is nil it worked. I don't know if that results in a memory leak though. I hope it doesn't. Thanks for the help!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests