Run time errors when app runs for the 1st time, to do with clearing display objects/groups?

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!

bump.

A “stack overflow” error is typically caused by recursion that continues without bound (you can typically recurse about 16,000 times before it happens).

Is it possible that your groups have a circular reference in them so that the loop that traverses them to clean them up gets stuck and eventually overflows the stack?

Perry Clark, thank you for your reply.

There is a recursion happening, if we put a print in the group.remove function then we see it is something like a circular reference. What has us completely stumped is that it only happens the first time the application is run. It also only happens in some daily builds, 2013.1095 for example.

Curiously we have just discovered that if we set “usesExpansionFile = false” in build.settings we don’t have this error. It only happens when we use expansion files.

local oldNewGroup = display.newGroup display.newGroup = function( ... ) &nbsp;&nbsp;&nbsp; local group = oldNewGroup( ... ) &nbsp;&nbsp;&nbsp; local oldRemoveSelf = group.removeSelf &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; group.removeSelf = function( self ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.numChildren then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for i = self.numChildren, 1, -1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self[i]:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oldRemoveSelf( self ) &nbsp;&nbsp;&nbsp; end &nbsp; &nbsp;&nbsp;&nbsp; group.remove = function( self, o ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if type( o ) == 'number' then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self[o]:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "group.remove removeSelf" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; return group end function cleanGroup( objectOrGroup ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; if objectOrGroup.numChildren then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while objectOrGroup.numChildren \> 0 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleanGroup ( objectOrGroup[objectOrGroup.numChildren]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; print "clean group" &nbsp;&nbsp;&nbsp; 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) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; testRoot:insert(testView) timer.performWithDelay(1000, function () cleanGroup(testRoot)&nbsp; end)

Here some more entries from our logs in case it’s related.

05-02 10:58:09.765: V/Corona(9207): \> Class.forName: network.LuaLoader 05-02 10:58:09.765: V/Corona(9207): \< Class.forName: network.LuaLoader 05-02 10:58:09.765: V/Corona(9207): Loading via reflection: network.LuaLoader 05-02 10:58:09.874: V/Corona(9207): \> Class.forName: CoronaProvider.licensing.google.LuaLoader 05-02 10:58:09.874: V/Corona(9207): \< Class.forName: CoronaProvider.licensing.google.LuaLoader 05-02 10:58:09.898: V/Corona(9207): Loading via reflection: CoronaProvider.licensing.google.LuaLoader 05-02 10:58:10.905: V/Corona(9207): \> Class.forName: widgetLibrary.widget\_progressView.LuaLoader 05-02 10:58:10.905: V/Corona(9207): Loading plugins: widgetLibrary.widget\_progressView.LuaLoader 05-02 10:58:10.937: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget\_progressView. 05-02 10:58:10.945: V/Corona(9207): \> Class.forName: widgetLibrary.widget.LuaLoader 05-02 10:58:10.945: V/Corona(9207): Loading plugins: widgetLibrary.widget.LuaLoader 05-02 10:58:10.984: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget. 05-02 10:58:11.366: V/Corona(9207): \> Class.forName: widgetLibrary.widget\_button.LuaLoader 05-02 10:58:11.366: V/Corona(9207): Loading plugins: widgetLibrary.widget\_button.LuaLoader 05-02 10:58:11.437: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget\_button. 05-02 10:58:11.437: V/Corona(9207): \> Class.forName: widgetLibrary.widget.LuaLoader 05-02 10:58:11.437: V/Corona(9207): Loading plugins: widgetLibrary.widget.LuaLoader 05-02 10:58:11.491: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget. 05-02 10:58:12.632: I/Corona(9207): clean group 05-02 10:58:12.632: I/Corona(9207): clean group 05-02 10:58:27.796: I/Corona(9207): ?:0: stack overflow 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'cleanGroup' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'cleanGroup' 05-02 10:58:27.796: I/Corona(9207): ?: in function '\_listener'

And also this mentioned licensing which might be affecting the expansion file.

05-02 10:58:11.601: W/System.err(9207): com.naef.jnlua.LuaRuntimeException: ?:0: attempt to index field '\_view' (a nil value) 05-02 10:58:11.601: W/System.err(9207): at com.naef.jnlua.LuaState.lua\_pcall(Native Method) 05-02 10:58:11.601: W/System.err(9207): at com.naef.jnlua.LuaState.call(Unknown Source) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.CoronaLua.dispatchEvent(CoronaLua.java:90) 05-02 10:58:11.601: W/System.err(9207): at CoronaProvider.licensing.google.LuaLoader$1.executeUsing(LuaLoader.java:276) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:153) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:274) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.Controller.onDrawFrame(Controller.java:233) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:379) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1622) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)

Here is an example the recreates the problem we are having.

Perry, perhaps you or some one could have a look at this example and see if they get the same error we do.  

We are out of ideas and hope this example will help some one help us.

bump.

A “stack overflow” error is typically caused by recursion that continues without bound (you can typically recurse about 16,000 times before it happens).

Is it possible that your groups have a circular reference in them so that the loop that traverses them to clean them up gets stuck and eventually overflows the stack?

Perry Clark, thank you for your reply.

There is a recursion happening, if we put a print in the group.remove function then we see it is something like a circular reference. What has us completely stumped is that it only happens the first time the application is run. It also only happens in some daily builds, 2013.1095 for example.

Curiously we have just discovered that if we set “usesExpansionFile = false” in build.settings we don’t have this error. It only happens when we use expansion files.

local oldNewGroup = display.newGroup display.newGroup = function( ... ) &nbsp;&nbsp;&nbsp; local group = oldNewGroup( ... ) &nbsp;&nbsp;&nbsp; local oldRemoveSelf = group.removeSelf &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; group.removeSelf = function( self ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.numChildren then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for i = self.numChildren, 1, -1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self[i]:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oldRemoveSelf( self ) &nbsp;&nbsp;&nbsp; end &nbsp; &nbsp;&nbsp;&nbsp; group.remove = function( self, o ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if type( o ) == 'number' then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self[o]:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "group.remove removeSelf" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o:removeSelf() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; return group end function cleanGroup( objectOrGroup ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; if objectOrGroup.numChildren then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while objectOrGroup.numChildren \> 0 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleanGroup ( objectOrGroup[objectOrGroup.numChildren]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; print "clean group" &nbsp;&nbsp;&nbsp; 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) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; testRoot:insert(testView) timer.performWithDelay(1000, function () cleanGroup(testRoot)&nbsp; end)

Here some more entries from our logs in case it’s related.

05-02 10:58:09.765: V/Corona(9207): \> Class.forName: network.LuaLoader 05-02 10:58:09.765: V/Corona(9207): \< Class.forName: network.LuaLoader 05-02 10:58:09.765: V/Corona(9207): Loading via reflection: network.LuaLoader 05-02 10:58:09.874: V/Corona(9207): \> Class.forName: CoronaProvider.licensing.google.LuaLoader 05-02 10:58:09.874: V/Corona(9207): \< Class.forName: CoronaProvider.licensing.google.LuaLoader 05-02 10:58:09.898: V/Corona(9207): Loading via reflection: CoronaProvider.licensing.google.LuaLoader 05-02 10:58:10.905: V/Corona(9207): \> Class.forName: widgetLibrary.widget\_progressView.LuaLoader 05-02 10:58:10.905: V/Corona(9207): Loading plugins: widgetLibrary.widget\_progressView.LuaLoader 05-02 10:58:10.937: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget\_progressView. 05-02 10:58:10.945: V/Corona(9207): \> Class.forName: widgetLibrary.widget.LuaLoader 05-02 10:58:10.945: V/Corona(9207): Loading plugins: widgetLibrary.widget.LuaLoader 05-02 10:58:10.984: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget. 05-02 10:58:11.366: V/Corona(9207): \> Class.forName: widgetLibrary.widget\_button.LuaLoader 05-02 10:58:11.366: V/Corona(9207): Loading plugins: widgetLibrary.widget\_button.LuaLoader 05-02 10:58:11.437: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget\_button. 05-02 10:58:11.437: V/Corona(9207): \> Class.forName: widgetLibrary.widget.LuaLoader 05-02 10:58:11.437: V/Corona(9207): Loading plugins: widgetLibrary.widget.LuaLoader 05-02 10:58:11.491: V/Corona(9207): Failed to write file: /data/data/net.studycat.funenglish.exasperation/cache/.system/resources/plugins.dex for library widgetLibrary.widget. 05-02 10:58:12.632: I/Corona(9207): clean group 05-02 10:58:12.632: I/Corona(9207): clean group 05-02 10:58:27.796: I/Corona(9207): ?:0: stack overflow 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'removeSelf' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'cleanGroup' 05-02 10:58:27.796: I/Corona(9207): ?: in function 'cleanGroup' 05-02 10:58:27.796: I/Corona(9207): ?: in function '\_listener'

And also this mentioned licensing which might be affecting the expansion file.

05-02 10:58:11.601: W/System.err(9207): com.naef.jnlua.LuaRuntimeException: ?:0: attempt to index field '\_view' (a nil value) 05-02 10:58:11.601: W/System.err(9207): at com.naef.jnlua.LuaState.lua\_pcall(Native Method) 05-02 10:58:11.601: W/System.err(9207): at com.naef.jnlua.LuaState.call(Unknown Source) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.CoronaLua.dispatchEvent(CoronaLua.java:90) 05-02 10:58:11.601: W/System.err(9207): at CoronaProvider.licensing.google.LuaLoader$1.executeUsing(LuaLoader.java:276) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:153) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:274) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.Controller.onDrawFrame(Controller.java:233) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:379) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1622) 05-02 10:58:11.601: W/System.err(9207): at com.ansca.corona.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)

Here is an example the recreates the problem we are having.

Perry, perhaps you or some one could have a look at this example and see if they get the same error we do.  

We are out of ideas and hope this example will help some one help us.