We use code heavily based on this approach to clean up our display objects and groups:
Proper Group Cleaning in Corona
Unfortunately using daily build 2013.1095 we have runtime errors that occur when the app first loads or if the app is loaded after clearing it’s data in the android application settings menu. We don’t have this problem with other daily builds (2013.1088 for example)
Here’s an example that’s taken from the lua source we use. We think the problem is that the display.newGroup, group.removeSelf and group.remove built in functions are being overridden. We’ve been doing this for a long time and we’re not sure why it’s breaking now.
local oldNewGroup = display.newGroup display.newGroup = function( ... ) local group = oldNewGroup( ... ) local oldRemoveSelf = group.removeSelf group.removeSelf = function( self ) if self.numChildren then for i = self.numChildren, 1, -1 do self[i]:removeSelf() end end oldRemoveSelf( self ) end group.remove = function( self, o ) if type( o ) == 'number' then self[o]:removeSelf() else o:removeSelf() end end return group end function cleanGroup( objectOrGroup ) if objectOrGroup.numChildren then while objectOrGroup.numChildren \> 0 do cleanGroup ( objectOrGroup[objectOrGroup.numChildren]) end end print "clean group" objectOrGroup:removeSelf() end local testRoot = display.newGroup() local testView = display.newGroup() local testText = display.newText("Adding new text to the testView display group", 0, 0, native.systemFont, 9) testText.x = 100 testText.y = 10 testView:insert(testText) testRoot:insert(testView) timer.performWithDelay(1000, function () cleanGroup(testRoot) end)
Looking at the log cat on the first run.
I/Corona ( 7472): clean group
I/Corona ( 7472): clean group
I/Corona ( 7472): Runtime error
I/Corona ( 7472): ?:0: stack overflow
I/Corona ( 7472): stack traceback:
I/Corona ( 7472): [C]: ?
I/Corona ( 7472): ?: in function ‘removeSelf’
I/Corona ( 7472): ?: in function ‘remove’
I/Corona ( 7472): ?: in function ‘?’
I/Corona ( 7472): ?: in function ‘removeSelf’
I/Corona ( 7472): ?: in function ‘remove’
I/Corona ( 7472): ?: in function ‘?’
I/Corona ( 7472): ?: in function ‘removeSelf’
I/Corona ( 7472): ?: in function ‘remove’
I/Corona ( 7472): ?: in function ‘?’
I/Corona ( 7472): ?: in function ‘removeSelf’
I/Corona ( 7472): …
I/Corona ( 7472): ?: in function ‘?’
I/Corona ( 7472): ?: in function ‘removeSelf’
I/Corona ( 7472): ?: in function ‘remove’
I/Corona ( 7472): ?: in function ‘?’
I/Corona ( 7472): ?: in function ‘removeSelf’
I/Corona ( 7472): ?: in function ‘cleanGroup’
I/Corona ( 7472): ?: in function ‘cleanGroup’
I/Corona ( 7472): ?: in function ‘_listener’
I/Corona ( 7472): ?: in function <?:141>
I/Corona ( 7472): ?: in function <?:218>
Force quit the app and start it again, results in
I/Corona ( 7514): clean group
I/Corona ( 7514): clean group
I/Corona ( 7514): clean group
Force quit the app, clear data and starting it again will make the runtime errors reappear.
Any insight would be very helpful!