remove object causes a crash of the simulator

The first bit of code is where I set up a collision event listener for my object. In build 268 everything works as expected. I am trying out the daily builds with no success on this project at all. I can get the item names and this is reported correctly. When it gets to the point of removing an item from screen the simulator crashes with any of the daily builds. Can anyone see what I am doing wrong that the daily builds would not like. I tried the display.remove(object) mentioned in one but had the same issue.

Cheers

Mike R

myObject.collision = destroyObject
myObject:addEventListener(“collision”,myObject)

[code]function destroyObject(self,event)
if gameActive == true then
local item1 = self
local item2 = event.other
if event.phase == “began” then
print (item1.name)
print (item2.name)
if item2.name == “Star” then
print ( item2.name) – Is the correct object.
item2:removeSelf()
item2 = nil
elseif item2.name == “Spike” then
splotX = self.x
splotY = self.y
item1:removeSelf()
item1 = nil
splatObject()
end
end
end
end
[import]uid: 9950 topic_id: 7719 reply_id: 307719[/import]

Wanted to add that outside of this function I can remove an object no problems at all. It is just in this previously working function I have an issue.

I changed a bit of the function so that knew that I am actually getting a single object and I am.

Cheers

Mike R

[code]if item2.name == “Star1” or item2.name == “Star2” or item2.name == “Star3” then
print ( item2.name)
item2:removeSelf()
item2 = nil

[import]uid: 9950 topic_id: 7719 reply_id: 27384[/import]

Make sure the item isn’t in transition when removing. You can’t access a number of properties if this is true. If it is, you have to make sure to cancel the tween first.

Now you can set the object properties:
item.isBodyActive = false
item:setLinearVelocity(0, 0)
item.angularVelocity = 0

And then you can remove the object. [import]uid: 11024 topic_id: 7719 reply_id: 27406[/import]

The object I am removing is static and has no listener applied to it. It just sits there waiting to be removed if it is touched by another object.

Cheers

Mike R [import]uid: 9950 topic_id: 7719 reply_id: 27410[/import]

Tried this and although it no longer crashed I get a nil returned when trying to remove the object using the normal object:removeSelf() afterward. If I don’t use that then it doesn’t remove anything and it still crashes.

Cheers

Mike R [import]uid: 9950 topic_id: 7719 reply_id: 27525[/import]

Yeah, I’m having random issues myself now. Havn’t figured out the problem yet. I’m guessing it has to be a bug from Corona since none of these issues occurred with the previous version [import]uid: 14018 topic_id: 7719 reply_id: 27546[/import]

The reason it didn’t occur in Corona before because the previous code had a bug, having memory leaked bug fixed it now exposes other problems on existing code that *did* work before, but now doesn’t.

The fix we introduced exposes errant code. Not the other way around.

C. [import]uid: 24 topic_id: 7719 reply_id: 27558[/import]

Is there any way to know what kind of invalid code it exposes? I can’t find the root cause of my crashes [import]uid: 14018 topic_id: 7719 reply_id: 27563[/import]

Found the problem! It seems that the object you’re trying to remove is in a group. Try do myGroup:remove(myObject) before removing the object. This solved it for me anyway:-) [import]uid: 14018 topic_id: 7719 reply_id: 27522[/import]

Ok. That’s fine but how do I fix that issue then?

I am following what seems to be normal practice in the documentation regarding setting listener events for collisions and then doing a self and other check for those collisions.

So how should I now be doing this? I am really confused as I am doing exactly what you say in the documents with the only addition of adding the object into a group.

Cheers

Mike R

Your sample code for local collisions from the docs.

I wanted to add that I get the same issue when trying to remove an object in a collision in your code as well.

So how are we supposed to remove objects safely using local collisions without crashing corona? I genuinely want to know as I cannot find any info on this at all.

[code]local crate1 = display.newImage( “crate.png” )
physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
crate1.myName = “first crate”

local crate2 = display.newImage( “crate.png” )
physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } )
crate2.myName = “second crate”

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

print( self.myName … ": collision began with " … event.other.myName )

elseif ( event.phase == “ended” ) then

print( self.myName … ": collision ended with " … event.other.myName )

end
end

crate1.collision = onLocalCollision
crate1:addEventListener( “collision”, crate1 )

crate2.collision = onLocalCollision
crate2:addEventListener( “collision”, crate2 ) [import]uid: 9950 topic_id: 7719 reply_id: 27566[/import]

I am getting around it for now using a global collision event.

This is working but are there any issues I am not seeing as to why this may still not be the correct way of doing things.

Cheers

Mike

[code]function destroyObject(event)
if gameActive == true then
local item1 = event.object1
local item2 = event.object2
if event.phase == “began” then
print (item1.name)
print (item2.name)
if item1.name == “Star1” or item1.name == “Star2” or item1.name == “Star3” then
print ( “Im a star”)
–item2:removeEventListener(“collision”,item2)
event.object1:removeSelf()
–item2:removeSelf()
–item = nil
end
end

Runtime:addEventListener(“collision”,destroyObject)
end
end [import]uid: 9950 topic_id: 7719 reply_id: 27586[/import]

I have the same problem. It works fine on PC(windows) but crashing on Mac on collision/removing physic body. I’m removing instances of an object, and they are created randomly so I have no idea how to work around that… Will this bug be fixed soon?

Cheers
[import]uid: 27699 topic_id: 7719 reply_id: 27592[/import]

Any words on how we remove an object using local collisions? I sent a request to support as I have tried numerous things and searched the documentation again and still keep finding the same info on how to do it that I am now told is how we should not be doing it.

Cheers

Mike R

Another example from the documentation :-

Note while Box2D objects will be safely retained until the end of the current world step, their Lua references will be deleted immediately. Therefore, be careful not to accidentally delete the same Lua object more than once. This situation could occur when deleting objects involved in collisions, which can potentially have many event phases before the collision is fully resolved. The solution is simple:

[code]local function onCollision( self, event )
if ( event.phase == “began” ) then

– Check if body still exists before removing!
if ( crate1 ) then
crate1:removeSelf()
crate1 = nil
end

end
end

[import]uid: 9950 topic_id: 7719 reply_id: 28070[/import]

did you see our latest twitter feed?

bug has been fixed. should be on the daily build.

C [import]uid: 24 topic_id: 7719 reply_id: 28290[/import]

Apologies. I meant to post that I had seen your tweet. Thank you.

Mike [import]uid: 9950 topic_id: 7719 reply_id: 28296[/import]

Hi,

i’m using the Corona SDK for 3 month now and I’m very happy about it.
I’m not a suscriber and I’m using the build 268 wich has this very important “remove object” bug. It leaves me no choice to stop the development of my app until you release the next public build.
I know, you will tell me to suscribe to get the daily build. But currently Corona doesn’t have all the features I need to complete my project so I won’t spend 200$ until those features are implemented.
But don’t get me wrong, I really enjoy using Corona and I understand it’s still a young SDK so I very hopeful and patient for its future.
Is there a way to download the previous build?

Thanks [import]uid: 25327 topic_id: 7719 reply_id: 29581[/import]

The 268 build doesn’t have the bug mentioned in this thread. There’s just something wrong with your code, if you post it in the dev. board someone might be able to help you [import]uid: 14018 topic_id: 7719 reply_id: 29583[/import]