testing prior to calling removeSelf()

I’m trying to escape the dreaded “attempt to remove an object that has already been removed” error…

Yes, I know it’s user error and I know we should be tracking all created display objs correctly in our code…so with all of that said, sometimes, in complex multi-screen apps, we lose track of one or two.

Does anyone have a good test for a “real” Corona display object (or group) that they use PRIOR to attempting to call removeSelf() on it?? [import]uid: 6175 topic_id: 17997 reply_id: 317997[/import]

My standard;

[lua]if obj ~= nil then
obj:removeSelf()
end[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 17997 reply_id: 68753[/import]

As a double sanity check you can also do this:

if obj ~= nil and object["removeSelf"] then  
 obj:removeSelf()  
end  

That way you can confirm that the object isn’t nil as well as if it actually has the removeSelf function confirming it is all fine to be removed.
[import]uid: 5833 topic_id: 17997 reply_id: 68754[/import]

Those would both be a little too general for my situation. I preferred Mikes test to see if the obj has the same MT as the stage but I’ve found a few times where the MT remains on a removed obj…thanks! [import]uid: 6175 topic_id: 17997 reply_id: 68757[/import]

That seems a very weird syntax to me…where did you find it documented??

display:removeSelf(Object)

Should be passing Object as P2, not as P1 (display goes into P1) and so I’m surprised it works [import]uid: 6175 topic_id: 17997 reply_id: 68785[/import]

I do not remember. At some time studying
I’m glad you solved his problem … =D [import]uid: 57267 topic_id: 17997 reply_id: 68788[/import]

Remember the : syntax implies that the first parameter is “self”, thus:

display.removeSelf(display,Object)

and

display:removeSelf(Object)

are the same calls.

[import]uid: 19626 topic_id: 17997 reply_id: 68790[/import]

Yes, I understand the syntax, but I don’t get your point…why would “display” get passed as “self” to the removeSelf() method…we’re not trying to remove display, we’re trying to remove “Object” so IT should be the “self” parameter…am I the only one who who thinks this is messed up??

Someone please show me where this is documented as I don’t want to depend on something undocumented that makes ZERO sense… [import]uid: 6175 topic_id: 17997 reply_id: 68817[/import]

#dgaedcke have to look after all we are talking about Display Object -> can only be the same in Docs.
But I do not see what else you want to understand what already explained above, if you have passed the reference of the object, no matter where it is, it is above or below, there are no objects with the same reference.
This need to study more calmly, and do not want to receive everything in the hands … -.~. [import]uid: 57267 topic_id: 17997 reply_id: 68818[/import]

Actually he makes a good point… Here is the relevant text from the removeSelf() API call:

http://developer.anscamobile.com/reference/index/objectremoveself

Parameters:

None

Returns:

Nothing
So to me, you are not allowed to pass things to removeSelf() [import]uid: 19626 topic_id: 17997 reply_id: 68822[/import]

Yeah…so unless #andre can show docs that prove Ansca officially supports this, I’m not inclined to use it as I don’t trust it to be supported in future revisions of the product [import]uid: 6175 topic_id: 17997 reply_id: 68824[/import]

rsrsrss… #dgaedcke You should trust more. I do not normally waste time. Blessed are those who believe without seeing … = D.
Look, you find more, will certainly continue to be supported by Ansca.

display.removeSelf (object) - check the same object can be in a different class, different, if the object ~ = nil then end, if this is in another class, will face problems if you remove the object … =o

http://developer.anscamobile.com/reference/index/displayremove [import]uid: 57267 topic_id: 17997 reply_id: 68827[/import]

Simple as Corona. I am amazed to see the work of some experienced users Corona them, without a need

display.removeSelf(Object) – checks whether the object was not removed before removing it. [import]uid: 57267 topic_id: 17997 reply_id: 68779[/import]

let’s talk on MSN: bessaandre@hotmail.com or SKYPE: andre-bessa

Hug! [import]uid: 57267 topic_id: 17997 reply_id: 68928[/import]

@andre – I wish you would stop with all of the Philosophy and innuendo and make sense instead. The docs you cite DO not support what you are doing and I can’t understand what you’ve written enough to tell if you even understand our question.

Yes, I’m trying to test whether the “instance” is either a display object or a group (i.e. some corona obj) and I don’t see you answering that question

I also don’t see any other Ansca staff or experienced dev’s jumping in to say they rely on this undocumented method u cite either. So unless you have a clear response to my question, please stop [import]uid: 6175 topic_id: 17997 reply_id: 68921[/import]

Hey Ansca,
Can we please get a RTTI api? There are times when I’m tracking objs apart from numChildren and my groups can get deeply nested and I’m occasionally hitting the “already removed” error in some cleanUp methods. In the absence of that, how about removing your _proxy or MT from the Lua table when the object is converted to a pure Lua table? I’d be totally willing to test the non-existence of those to determine that it’s not a Corona obj.

Thx
D [import]uid: 6175 topic_id: 17997 reply_id: 69859[/import]

Hey dgaedcke,

Could you please post this in the feature request subforum? (The subscriber one, not the public one.)

I can move threads but not posts and having it there means it can be properly added to the pile :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 17997 reply_id: 69862[/import]

I know this is an old thread, but I came up against this same question, and here are the official Corona Labs docs supporting the use of display.remove(object). @andrebessa had the syntax slightly wrong, but in general was correct.
[import]uid: 149111 topic_id: 17997 reply_id: 126451[/import]

I know this is an old thread, but I came up against this same question, and here are the official Corona Labs docs supporting the use of display.remove(object). @andrebessa had the syntax slightly wrong, but in general was correct.
[import]uid: 149111 topic_id: 17997 reply_id: 126451[/import]