Tableview Crash?

I’m using tableView 2.0, latest build 1080.

Just trying to retreive the highscores from Corona Cloud, and add them to the tableview.

Runs fine in the simulator, but crashes on Kindle Fire and iPad.

I narrowed it down to the tableView, as soon as I start adding items.

Maybe I missed something, can anybody check my code for errors?

[lua]

local storyboard = require( “storyboard” )

local widget = require “widget”

local scene = storyboard.newScene()

local Click = audio.loadSound(“sounds/clickbutton.mp3”)

local http = require(“socket.http”)

local ltn12 = require(“ltn12”)

local _W = display.contentWidth 

local _H = display.contentHeight


– BEGINNING OF YOUR IMPLEMENTATION


– Called when the scene’s view does not exist:

function scene:createScene( event )

    print(“CREATE SCENE LEADERBOARD”)    

    local group = self.view

    

            – BG IMAGE

    Background       = display.newImage(“images/leaderboard.jpg”)

    group:insert(Background)

    local Exit = function(event)

        if event.phase == “ended” then

            audio.play ( Click )    

            tableView:removeSelf()

            tableView = nil    

            Runtime:removeEventListener( “Leaderboards”, ccShowScores )

            storyboard.gotoScene( “menu”, “fade”, 400  )                

        end

    end

    

    local ExitButton = widget.newButton{

        left = _W/2,

        top = 940,

        defaultFile = “images/btnExit.png”,

        overFile = “images/btnExitS.png”,

        onRelease = Exit

    }

    

    ExitButton.x = _W/2

    group:insert(ExitButton)

        

    function comma_value(n) – credit http://richard.warburton.it

        local left,num,right = string.match(n,’^([^%d]*%d)(%d*)(.-)$’)

        return left…(num:reverse():gsub(’(%d%d%d)’,’%1,’):reverse())…right

    end

    

    – onRender listener for the tableView

    local function onRowRender( event )

            local row = event.row

        

            User = score[row.index].username        

            xText = tostring(row.index)…". "…score[row.index].username

            local text = display.newText( row, xText, 0, 0,nil, 25 )

            text:setReferencePoint( display.CenterLeftReferencePoint )

            text.y = row.contentHeight * 0.5

            

            local score = display.newText( row, comma_value(score[row.index].value), 0, 0, nil, 25 )

            score:setReferencePoint( display.CenterRightReferencePoint )

            score.y = row.contentHeight * 0.5 

            score.x = 550

            

            if not row.isCategory then

                if _G.PlayerName == User then

                    text:setTextColor( 0, 255, 0 )

                    score:setTextColor( 0, 255, 0 )

                end    

            end

    

    end

    

    function ccShowScores( event )

            

        score = {}

        

        local results = event.results

        local maxScores = #results

        

        if ( maxScores > 100 ) then maxScores = 100 end  --get maximum of 100 high scores

        

        for i = 1, maxScores do

            score[i] = {}

            score[i].username = string.sub(results[i].username, 1, 15)

            score[i].value = results[i].value

            

            local rowHeight, rowColor, lineColor, isCategory

            local isCategory = false

            

            – function below is responsible for creating the row

            – Insert the row into the tableView

            print(“Add item to tableview”)

            

            tableView:insertRow

            {

                isCategory = isCategory,

                rowHeight = 40,

                rowColor = { 

                    default = { 255, 255, 255, 0 },

                }                

            }        

            

            

        end

    end

    – Create a tableView

    tableView = widget.newTableView

    {

        left = 115,

        top = 315,

        width = 554,    

        height = 554,

        noLines = true,

        maskFile = “mask.png”,

        hideBackground = true,

        onRowRender = onRowRender,

    }    

        

    Runtime:addEventListener( “Leaderboards”, ccShowScores )

    coronaCloud.authToken = _G.UserToken

    local leaderboardID = “512f9bae649329b106000005”  --your leaderboard ID

    

    function GetHighscore()

        coronaCloud.getLeaderboardScores( leaderboardID ) 

    end

    

    timer.performWithDelay( 500, GetHighscore )

         

end

– Called BEFORE scene has moved onscreen:

function scene:willEnterScene( event )

        local group = self.view

end

– Called immediately after scene has moved onscreen:

function scene:enterScene( event )

        local group = self.view

        -----------------------------------------------------------------------------

        –      INSERT code here (e.g. start timers, load audio, start listeners, etc.)

        -----------------------------------------------------------------------------

end

– Called when scene is about to move offscreen:

function scene:exitScene( event )

        local group = self.view

        -----------------------------------------------------------------------------

        –      INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)

        -----------------------------------------------------------------------------

end

– Called AFTER scene has finished moving offscreen:

function scene:didExitScene( event )

        local group = self.view

        -----------------------------------------------------------------------------

        –      This event requires build 2012.782 or later.

        -----------------------------------------------------------------------------

end

– Called prior to the removal of scene’s “view” (display group)

function scene:destroyScene( event )

        local group = self.view

        -----------------------------------------------------------------------------

        –      INSERT code here (e.g. remove listeners, widgets, save state, etc.)

        -----------------------------------------------------------------------------

end

– Called if/when overlay scene is displayed via storyboard.showOverlay()

function scene:overlayBegan( event )

        local group = self.view

        local overlay_name = event.sceneName  – name of the overlay scene

        -----------------------------------------------------------------------------

        –      This event requires build 2012.797 or later.

        -----------------------------------------------------------------------------

end

– Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()

function scene:overlayEnded( event )

        local group = self.view

        local overlay_name = event.sceneName  – name of the overlay scene

        -----------------------------------------------------------------------------

        –      This event requires build 2012.797 or later.

        -----------------------------------------------------------------------------

end


– END OF YOUR IMPLEMENTATION


– “createScene” event is dispatched if scene’s view does not exist

scene:addEventListener( “createScene”, scene )

– “willEnterScene” event is dispatched before scene transition begins

scene:addEventListener( “willEnterScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished

scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins

scene:addEventListener( “exitScene”, scene )

– “didExitScene” event is dispatched after scene has finished transitioning out

scene:addEventListener( “didExitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be

– automatically unloaded in low memory situations, or explicitly via a call to

– storyboard.purgeScene() or storyboard.removeScene().

scene:addEventListener( “destroyScene”, scene )

– “overlayBegan” event is dispatched when an overlay scene is shown

scene:addEventListener( “overlayBegan”, scene )

– “overlayEnded” event is dispatched when an overlay scene is hidden/removed

scene:addEventListener( “overlayEnded”, scene )


return scene

[/lua]