Example of what I am doing. It is probably not exactly the same as Steve’s error but I am sure it is related.
[lua]
– in the simulator this re-produces the error if we
– override the display.newGroup function below
– require(“widget”)
– using this modified widget file that makes cached_displayNewGroup()
– a global works in the simulator but not on device.
– require(“widgetLibrary.widget”)
– function display.newGroup()
– return cached_displayNewGroup()
– end
– Just for example, this override causes a recursive loop on first load
– on a device. We don’t use this anymore, as long as we don’t override
– anything we’re fine. This override could be commented out and this
– example will still run. fine.
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
print “group.remove removeSelf”
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)
[/lua]