Changing scene using tableview onRowTouch causes "bad argument #-2" sometimes

Hi All,

I am slowly getting familiar with Corona but its a painful process so far.

Here is my current dilemma!

I have a app that uses storyboard’s and for the most part it works perfectly fine, however every now and then, when tapping on a tableview, it crashes with :

Bad argument #-2 to 'insert' (Proxy expected, got nil) stack traceback: [C]: ? [C]: in function 'insert' ?: in function '?' ?: in function 'gotoScene' ....browse.lua:226:in function '\_onRowTouch' ?: in function \<?:516\> ?: in function \<?:218\>

Now here is the weird part. This only happens SOMETIMES. most of the time I can click on a table entry, and it will correctly switch to the detail storyboard, and go back and forth without issue. However sometimes as soon as I click or drag the table this error comes up.

Sometimes I will go into an entries details, come back to the browse screen and click the entry again and have this error show up. I have no idea at all what is causing it.

this is my onRowTouch event :

local function onRowTouch( event ) &nbsp; if event then &nbsp;&nbsp;&nbsp; local phase = event.phase &nbsp;&nbsp;&nbsp; local row = event.target &nbsp;&nbsp;&nbsp; local temp = {} &nbsp;&nbsp;&nbsp; temp[1] = listrecs[row.index].company &nbsp;&nbsp;&nbsp; temp[2] = listrecs[row.index].offer &nbsp;&nbsp;&nbsp; temp[3] = listrecs[row.index].address &nbsp;&nbsp;&nbsp; temp[4] = listrecs[row.index].text &nbsp;&nbsp;&nbsp; temp[5] = listrecs[row.index].catagories &nbsp;&nbsp;&nbsp; temp[6] = listrecs[row.index].distance &nbsp;&nbsp;&nbsp; storyboard.detail\_data = temp &nbsp;&nbsp;&nbsp; temp = nil &nbsp;&nbsp;&nbsp; storyboard.previous\_scene = "browse" &nbsp;&nbsp;&nbsp; storyboard.gotoScene( "details" ) &nbsp;&nbsp;&nbsp; return true &nbsp; end end

I did have purgeScene in the ExitScene function of the Browse storyboard, I tried removing it, moving it to details storyboard but to no effect.

the CreateScene of the details storyboard only has one button and 4 text objects placed in scene. no other special or advanced stuff.

The error is really not helpful, can a guru perhaps fill me in on what this error means, and how it could work sometimes?

Finally, I am willing to post all of my code (theres a lot) if you want to see the whole thing

Thankyou all!

I’ve seen similar crash log but not with tableView.

The reason should be related with how & where you handle the purgeScene()

You may want to show the code for exitScene() & didExitScene() at least for a initial diagnosis

My quick guess, try to put your purgeScene() in didExitScene(), see if it helps.

Unfortunately the exitscene, didexitscene and destroyscene are emtpy in storyboard “browse”  and in storyboard “details” only exitscene has code to remove the native map.

to purge the scene, I capture the name of the current scene, store it into a variable, and then purge the previous scene in createScene of the current storyboard.

–removed code

(1) what if you comment out the purgeScene() in “detail”'s createScene(), does the crash still happen?

If not, the crash must be related to how you handle purgeScene()

(2) as I recommended, try to put purgeScene(“browse”) in “browse” didExitScene(), does the crash still happen?

OK, that seems to have fixed it.  It only happens sometimes but I just clicked like 50 times and it did not crash.

Legendary joe528.  Thankyou for your help and patience!

Maybe I spoke to soon. although it has not crashed, purgescene does not execute when in didExitScene()

unless didExitScene() is not executed…

try to print something in didExitScene() to see if didExitScene() is executed

I assume you forgot to add this line?

scene:addEventListener( "didExitScene", scene)

Can I swap brains with you please?  You clearly know what I am doing wrong before I do :stuck_out_tongue:

That has done it (wow I feel stupid)
 

while I have your attention, another error that comes up once or twice a day (like just now) is this :

?:0 attempt to perform arithmatic on field 'contentHeight' (a nil value) stack traceback : [C]: ? ?: in function '\_manageRowLifeCycle' ?: in function \<?:516\> ?: in function \<?:218\>

This happens when scrolling or tapping

In basic operations, Corona is quite solid, so that was the only possibility.

But for your last question, I have no clue… maybe you need to show your code again.

By the way, the reason you got the crash is because you call purgeScene() in the new scene’s createScene()

This is not a good implementation, don’t do this at all.

For example, when sceneA --> call gotoScene(“sceneB”)

From my observation, sceneB’s createScene() might be called before sceneA completely exits. Therefore, your purgeScene (to clean up sceneA) “sometimes” is executed before sceneA exits, hence the crash. If you are lucky, purgeScene is called after sceneA exits, then there is no crash. That is why you see the crash “SOMETIMES”.

I’ve seen similar crash log but not with tableView.

The reason should be related with how & where you handle the purgeScene()

You may want to show the code for exitScene() & didExitScene() at least for a initial diagnosis

My quick guess, try to put your purgeScene() in didExitScene(), see if it helps.

Unfortunately the exitscene, didexitscene and destroyscene are emtpy in storyboard “browse”  and in storyboard “details” only exitscene has code to remove the native map.

to purge the scene, I capture the name of the current scene, store it into a variable, and then purge the previous scene in createScene of the current storyboard.

–removed code

(1) what if you comment out the purgeScene() in “detail”'s createScene(), does the crash still happen?

If not, the crash must be related to how you handle purgeScene()

(2) as I recommended, try to put purgeScene(“browse”) in “browse” didExitScene(), does the crash still happen?

OK, that seems to have fixed it.  It only happens sometimes but I just clicked like 50 times and it did not crash.

Legendary joe528.  Thankyou for your help and patience!

Maybe I spoke to soon. although it has not crashed, purgescene does not execute when in didExitScene()

unless didExitScene() is not executed…

try to print something in didExitScene() to see if didExitScene() is executed

I assume you forgot to add this line?

scene:addEventListener( "didExitScene", scene)

Can I swap brains with you please?  You clearly know what I am doing wrong before I do :stuck_out_tongue:

That has done it (wow I feel stupid)
 

while I have your attention, another error that comes up once or twice a day (like just now) is this :

?:0 attempt to perform arithmatic on field 'contentHeight' (a nil value) stack traceback : [C]: ? ?: in function '\_manageRowLifeCycle' ?: in function \<?:516\> ?: in function \<?:218\>

This happens when scrolling or tapping

In basic operations, Corona is quite solid, so that was the only possibility.

But for your last question, I have no clue… maybe you need to show your code again.

By the way, the reason you got the crash is because you call purgeScene() in the new scene’s createScene()

This is not a good implementation, don’t do this at all.

For example, when sceneA --> call gotoScene(“sceneB”)

From my observation, sceneB’s createScene() might be called before sceneA completely exits. Therefore, your purgeScene (to clean up sceneA) “sometimes” is executed before sceneA exits, hence the crash. If you are lucky, purgeScene is called after sceneA exits, then there is no crash. That is why you see the crash “SOMETIMES”.