widget.newTableView().reloadData() crashes app

I have an app that behaves good in most cases, but in the special case of being run the very first time after a clean install on a device it crashes in a call to the reloadData() method of a newTableView() object:

I/Corona ( 8723): /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget\_tableview.lua:1595: attempt to index field '?' (a nil value) I/Corona ( 8723): stack traceback: I/Corona ( 8723): /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget\_tableview.lua:1595: in function \</Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget\_tableview.lua:1580\> I/Corona ( 8723): (tail call): ? I/Corona ( 8723): ?: in function 'method' I/Corona ( 8723): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lua:253: in function 'dispatchEvent' I/Corona ( 8723): /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/composer/composer.lua:886: in function \</Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/composer/composer.lua:865\> I/Corona ( 8723): (tail call): ? I/Corona ( 8723): /Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/transition/transition.lua:588: in function 'method' I/Corona ( 8723): /Users/jenkins/slaveroot/workspace/Templates/label/android/platform/resources/init.lu

Now, as far as I know what (ther misnamed?) reloadData() method does is to re-render the visible rows of a table (http://docs.coronalabs.com/api/type/TableViewWidget/reloadData.html).

So according to my logic calling reloadData() would lead to a immediate call to the specified onRowRender() function (one call per visible row).

But this is not what happens. I’ve put print statements inside the onRowRender() function and the crash happens even before this function is called once.

So I’m out of options as I have no idea what causes the crash. My guess is that there is something wrong with the newTableView object itseld, but how do I check this (it’s not nil, that’s the only think I’m sure of).

Hi @runewinse,

We’d need to see your code pertaining to this, not just the error report. There are too many potential variances to understand what might be the issue.

Brent

Hi,

The following code seems to do the job of making the app crash:

local widget = require("widget") \_W = display.contentWidth \_H = display.contentHeight catTable = widget.newTableView { x = \_W\*0.5, y = \_H\*0.5, height = \_H\*0.5, width = \_W\*0.5, } catTable:reloadData()

In my case, the number of table items was in a certain case 0 (no insertRow called) and that is enough to make the widget crash if reloadDataI() is called.

Windows simulator and Android device.

One could argue that reloadData() should not be called on empty tables, but this is a SDK and a certain robustness against such things would be nice.

Interesting! There were a lot of changes in the last month or so to tableview (I posted about two bugs that have, I believe, been fixed in recent daily builds). I suspect that might be causing this crash. But, as you say, robustness is expected.

While this can easily be worked around:

if object:getNumRows() > 0 then

    object:reloadData()

end

you’re right, something like this needs to not error out.   Please file a bug report using the link at the top of the page.  Make sure to include your config.lua and build.settings and put it in a .zip file.

Thanks

Rob

Hi @runewinse,

We’d need to see your code pertaining to this, not just the error report. There are too many potential variances to understand what might be the issue.

Brent

Hi,

The following code seems to do the job of making the app crash:

local widget = require("widget") \_W = display.contentWidth \_H = display.contentHeight catTable = widget.newTableView { x = \_W\*0.5, y = \_H\*0.5, height = \_H\*0.5, width = \_W\*0.5, } catTable:reloadData()

In my case, the number of table items was in a certain case 0 (no insertRow called) and that is enough to make the widget crash if reloadDataI() is called.

Windows simulator and Android device.

One could argue that reloadData() should not be called on empty tables, but this is a SDK and a certain robustness against such things would be nice.

Interesting! There were a lot of changes in the last month or so to tableview (I posted about two bugs that have, I believe, been fixed in recent daily builds). I suspect that might be causing this crash. But, as you say, robustness is expected.

While this can easily be worked around:

if object:getNumRows() > 0 then

    object:reloadData()

end

you’re right, something like this needs to not error out.   Please file a bug report using the link at the top of the page.  Make sure to include your config.lua and build.settings and put it in a .zip file.

Thanks

Rob