It’s difficult to understand what caused the stack overflow without more details…
The attached snippet works for me as expected (save as main.lua and run):
[lua]local coronaMetaTable = getmetatable(display.getCurrentStage())
— Returns whether aDisplayObject is a Corona display object.
– note that all Corona types seem to share the same metatable, which is used for the test.
–@param aDisplayObject table - possible display object.
–@return boolean - true if object is a display object
local isDisplayObject = function(aDisplayObject)
return (type(aDisplayObject) == “table” and getmetatable(aDisplayObject) == coronaMetaTable)
end
local function cleanGroups ( objectOrGroup )
if(not isDisplayObject(objectOrGroup)) then return end
if objectOrGroup.numChildren then
– we have a group, so first clean that out
while objectOrGroup.numChildren > 0 do
– clean out the last member of the group (work from the top down!)
cleanGroups ( objectOrGroup[objectOrGroup.numChildren])
end
end
– we have either an empty group or a normal display object - remove it
objectOrGroup:removeSelf()
return
end
local o = display.newCircle(100,100,10)
local g = display.newGroup()
for i = 1,100 do
local lg = display.newGroup()
lg:insert(display.newCircle(math.random(200),math.random(300),math.random(100)))
g:insert(lg)
end
print(“before info”)
print(“o.numChildren”,o and o.name, o and o.numChildren, isDisplayObject(o))
print(“g.numChildren”,g and g.name, g and g.numChildren, isDisplayObject(g))
local info = function()
print(“before cleanGroups”)
print(“o.numChildren”,o and o.name, o and o.numChildren, isDisplayObject(o))
print(“g.numChildren”,g and g.name, g and g.numChildren, isDisplayObject(g))
cleanGroups ( o )
cleanGroups ( g )
print(“after cleanGroups”)
print(“o.numChildren”,o and o.name, o and o.numChildren, isDisplayObject(o))
print(“g.numChildren”,g and g.name, g and g.numChildren, isDisplayObject(g))
end
timer.performWithDelay(3000, info, 1)[/lua]
-FrankS.
[import]uid: 8093 topic_id: 7489 reply_id: 26613[/import]