I have been working on a “Restart” function for our business app. The issue we have is that on IOS if the App has an error we catch it, navigate to a error page which allows them to log the issue, and present a “Restart” button. We need to restart as we want to reset the App to a stable base. However, there is no restart option on IOS so we are trying to build our own.
What I want to do is to remove all of the display objects that I may currently be using. To do this I have written the below function: -
local storyboard = require "storyboard" local tmid local function ClearStage(Grp,bs) if Grp ~= nil then if Grp.numChildren ~= nil then for i = 1, Grp.numChildren do ClearStage(Grp[1],bs+1) end end if bs \> 2 then Grp:removeSelf() Grp = nil end end end local function onSystemEvent(event) if ((event.type == "applicationSuspend") and (\_G.CameraLoaded == nil)) then if tmid ~= nil then timer.cancel(tmid) tmid = nil end end if ((event.type == "applicationResume") and (\_G.CameraLoaded == nil)) then local stage = display.getCurrentStage() ClearStage(stage,0) local LoadSplash = function() return storyboard.gotoScene( "splash", "fade", 100 ) end tmid = timer.performWithDelay( 1500, LoadSplash, 1 ) end end Runtime:addEventListener("system", onSystemEvent)
This seems to work, however if you see the function ClearStage I only clear down the children of the children of the base stage.
local function ClearStage(Grp,bs) if Grp ~= nil then if Grp.numChildren ~= nil then for i = 1, Grp.numChildren do ClearStage(Grp[1],bs+1) end end if bs \> 2 then Grp:removeSelf() Grp = nil end end end
If I clear down the children of the base group I get this error from the storyboard class: -
ERROR: Runtime error
C:…\storyboard.lua:617: attempt to index local ‘bounds’ (a nil value)
stack traceback:
C:…\storyboard.lua:617: in function ‘saveSceneAndHide’
C:…\storyboard.lua:1627: in function <C:…\storyboard.lua:1560>
(tail call): ?
?: in function ‘?’
?: in function <?:190>
I would really like to understand what is happening with this. I have checked the base stage and on Main if I run the following code: -
print(stage.numChildren) local storyboard = require "storyboard" print(stage.numChildren)
I get: -
0
1
So the require “storyboard” creates a base group.
But what I don’t understand is if I remove all of the children of this base group I get the above error?