[HELP] App runs perfectly on iOS, but with errors on Android

It runs great on iOS with no runtime errors etc, also on the simulator. But I don’t know why it is returning some errors while trying to test it on a Galaxy Tab 4 running on 4.4.2. Here’s what I get:

(after going to main menu from the canvas)
 

wEFTJLL.png

(after selecting some picture to paint (it doesn’t happen on all pics))

SYcI0Tn.png

it also returns an error after leaving the device screen sleep, then waking it again.

Can you post the code where you get those errors?

Well uhm, the first is coming from the widget library as you can see, the second…

[lua]

function toggleBtns( activeBtnId )    
    
    local this_btn = nil
    local isActive = false
    for i=1, btns_sprt.numChildren do
        this_btn = btns_sprt[i]
        if ( this_btn ~= nil ) then
            isActive = ( i == activeBtnId )
            this_btn[1].isVisible = isActive
            this_btn[2].isVisible = not isActive
        end
    end
    
end

[/lua]

Hi @waelisnothing,

For #1, we’ll still need to see your widget code and perhaps some of the surrounding code as well. The error hints that you’re attempting to “fill” an object which doesn’t exist.

For #2, this means that “btns_sprt.numChildren” is not a display group containing children, so it’s not giving you back a number, and thus the Lua “for” loop is failing.

Best regards,

Brent

I am using the “widget-v1” lib
 

Menu button:
[lua]
    local goMenu = function()
        – Handler that gets notified when the alert closes
        local function onComplete( event )
            if “clicked” == event.action then
                local i = event.index
                if 1 == i then
                    createBlankBase()
                    display.getCurrentStage():setFocus(nil)
                    storyboard.gotoScene( “mainMenu”, “crossFade”, 400 )
                elseif 2 == i then
                    – Do nothing; dialog will simply dismiss
                end
            end
        end
        – Show alert with Options. Trigger the wipe action * Return to Menu if the user clicks the 1st button.
        local alert = native.showAlert( “Return to Menu?”, “Are you sure you want to return to the Menu?”,  { “Yes”, “Cancel” }, onComplete )
    
        return true
    end

    local menuButton = widget.newButton{
            left = configPanel.x+87,
            top = configPanel.y-85,
            default = guiImages…“buttonMenuOff.png”,
            over = guiImages…“buttonMenuOn.png”,
            onRelease = goMenu
            }   

[/lua]

Well why #2 works flawlessly on iOS but not Android?
 

Hello,

Error #2 isn’t coming from the button widget, it’s coming from “slider.lua”…

Brent

Here’s the slider.lua code, but I asked for clarification, why does it work on iOS, but not on Android?
[lua]
module( …, package.seeall )

– Slider, created by Microsheep, microsheep.com
– You can see it working in my game - Fingerless 3D
– Free to use, feel free to change, but please share it with the community

– vars
local slider_sprt        = nil
local slides_sprt        = nil
local btns_sprt            = nil

local isDragging        = false
local currSlideIndex    = 1
local startPosX            = 0
local offsetPosX        = 0
local lastPosX            = 0
local lastTimeMsec        = 0
local dX                = 0
local slide_twn            = nil

– forward declerations
local touchCb
local slideEndCb
local toggleBtns
local startDrag
local endDrag
local drag
local slideTo

–##################################################################################################
– PUBLIC METHODS
–##################################################################################################


– init

function init()

    – vars
    slider_sprt        = nil
    slides_sprt        = nil
    btns_sprt        = nil

    isDragging        = false
    currSlideIndex    = 1
    startPosX        = 0
    offsetPosX        = 0
    lastPosX        = 0
    lastTimeMsec    = 0
    dX                = 0
    slide_twn        = nil
    
    – slider_sprt
    slider_sprt = display.newGroup()
    
    – slides_sprt
    slides_sprt = display.newGroup()
    slider_sprt:insert( slides_sprt )
    
    – btns_sprt
    btns_sprt = display.newGroup()
    slider_sprt:insert( btns_sprt )
    
    – events
    slides_sprt:addEventListener( “touch”, touchCb )
    --Runtime:addEventListener( “touch”, touchCb )
    
end


– dispose

function dispose()
    
    – events
    slides_sprt:removeEventListener( “touch”, touchCb )
    --Runtime:removeEventListener( “touch”, touchCb )
    
    – cancel tween
    if ( slide_twn ~= nil ) then
        transition.cancel( slide_twn )
        slide_twn = nil
    end
    
    – btns_sprt
    local thisBtn = nil
    while ( btns_sprt.numChildren > 0 ) do
        thisBtn = btns_sprt[1]
        for j=1, thisBtn.numChildren do
            thisBtn:remove( 1 )
        end
        thisBtn:removeEventListener( “tap”,  tapCb)
        btns_sprt:remove( thisBtn )
    end
    slider_sprt:remove( btns_sprt )
    btns_sprt = nil
    
    – slides_sprt
    slides_sprt = display.newGroup()
    
    local thisSlide_sprt = nil
    while ( slides_sprt.numChildren > 0 ) do
        --thisSlide_sprt.dispose()
        thisSlide_sprt = slides_sprt[1]
        slides_sprt:remove( thisSlide_sprt )
    end
    slider_sprt:remove( slides_sprt )
    slides_sprt = nil
    
    – slider_sprt
    
    – vars

end


– getSprite

function getSprite()

    return slider_sprt
    
end


– getSlide

function getSlide( slideIndex )

    return slides_sprt[slideIndex]
    
end


– setState

function addSlide( slide_sprt, btn_sprt )
    
    – slide
    slides_sprt:insert( slide_sprt )
    slide_sprt.x = (slides_sprt.numChildren - 1) * display.contentWidth
    
    – btn
    if ( btn_sprt ~= nil ) then
        btns_sprt:insert( btn_sprt )
        btn_sprt:addEventListener( “tap”,  tapCb)
        toggleBtns( 1 )
    end
    
end

–##################################################################################################
– PRIVATE METHODS
–##################################################################################################


– touchCb

function touchCb( evt )
    
    if (evt.phase == “began”) then
        startDrag( evt )
    elseif (evt.phase == “ended”) then
        endDrag( evt )
    else
        drag( evt )
    end
    
end


– slideEndCb

function slideEndCb( evt )
    
    – currSlideIndex
    currSlideIndex = 1 + math.floor( (-slides_sprt.x + 0.5 * display.contentWidth) / display.contentWidth )
    – offsetPosX
    offsetPosX = slides_sprt.x
    – btns
    toggleBtns( currSlideIndex )
    
end


– tapCb

function tapCb( evt )
    
    local btnId = evt.target.id
    --toggleBtns( btnId )
    slideTo( btnId, 2500 )
    
end


– toggleBtns

function toggleBtns( activeBtnId )    
    
    local this_btn = nil
    local isActive = false
    for i=1, btns_sprt.numChildren do
        this_btn = btns_sprt[i]
        if ( this_btn ~= nil ) then
            isActive = ( i == activeBtnId )
            this_btn[1].isVisible = isActive
            this_btn[2].isVisible = not isActive
        end
    end
    
end


– startDrag

function startDrag( evt )
    
    isDragging = true
    
    – startPosX
    --startPosX = evt.xStart
    startPosX = evt.x
    
    – offsetPosX
    offsetPosX = slides_sprt.x
    
    – lastPosX and lastTimeMsec
    lastPosX = evt.x
    lastTimeMsec = system.getTimer()
    
    – cancel tween
    if ( slide_twn ~= nil ) then
        transition.cancel( slide_twn )
        slide_twn = nil
    end
    
end


– endDrag

function endDrag( evt )
    
    isDragging = false
    
    – calc speed
    local dT = system.getTimer() - lastTimeMsec
    if (dT < 10) then dT = 10 end
    local speed = dX / ( 0.001 * dT )
    
    – targetSlideIndex
    local targetSlideIndex = currSlideIndex
    
    if (math.abs(speed) > 500) then
        – speed
        targetSlideIndex = targetSlideIndex - (speed / math.abs(speed))
    else
        targetSlideIndex = 1 + math.floor( (-slides_sprt.x + 0.5 * display.contentWidth) / display.contentWidth )
        speed = 1000
    end
    
    – min / max slide index
    if ( targetSlideIndex <= 0 or targetSlideIndex >  slides_sprt.numChildren) then
        targetSlideIndex = currSlideIndex
        speed = 1000
    end
    
    – slide tween
    slideTo( targetSlideIndex, speed )
    
end


– drag

function drag( evt )
    
    if ( false == isDragging ) then
        startDrag( evt )
        startPosX = evt.x
    end
    
    – lastPosX and lastTimeMsec
    dX = evt.x - lastPosX
    lastPosX = evt.x
    lastTimeMsec = system.getTimer()
    
    – pos
    --slides_sprt.x = offsetPosX + evt.x - evt.xStart
    slides_sprt.x = offsetPosX + evt.x - startPosX
    
end


– slideTo

function slideTo( targetSlideIndex, speed )
    
    – cancel tween
    if ( slide_twn ~= nil ) then
        transition.cancel( slide_twn )
        slide_twn = nil
    end
    
    – tween
    local targetPosX = (targetSlideIndex - 1) * display.contentWidth
    local timeMsec = 1000 * math.abs( (slides_sprt.x + targetPosX) / speed )
    --slide_twn = transition.to( slides_sprt, { x = -targetPosX, time = timeMsec, transition = easing.inOutQuad, onComplete = slideEndCb } )
    slide_twn = transition.to( slides_sprt, { x = -targetPosX, time = timeMsec, onComplete = slideEndCb } )
    
end
[/lua]

Hi @waelisnothing,

I don’t really know why it would fail on Android but not iOS, unless there’s some issue with your “module( …, package.seeall )” inclusion. This should not be used any longer, as it was long ago deprecated in Lua.

Brent

Can you post the code where you get those errors?

Well uhm, the first is coming from the widget library as you can see, the second…

[lua]

function toggleBtns( activeBtnId )    
    
    local this_btn = nil
    local isActive = false
    for i=1, btns_sprt.numChildren do
        this_btn = btns_sprt[i]
        if ( this_btn ~= nil ) then
            isActive = ( i == activeBtnId )
            this_btn[1].isVisible = isActive
            this_btn[2].isVisible = not isActive
        end
    end
    
end

[/lua]

Hi @waelisnothing,

For #1, we’ll still need to see your widget code and perhaps some of the surrounding code as well. The error hints that you’re attempting to “fill” an object which doesn’t exist.

For #2, this means that “btns_sprt.numChildren” is not a display group containing children, so it’s not giving you back a number, and thus the Lua “for” loop is failing.

Best regards,

Brent

I am using the “widget-v1” lib
 

Menu button:
[lua]
    local goMenu = function()
        – Handler that gets notified when the alert closes
        local function onComplete( event )
            if “clicked” == event.action then
                local i = event.index
                if 1 == i then
                    createBlankBase()
                    display.getCurrentStage():setFocus(nil)
                    storyboard.gotoScene( “mainMenu”, “crossFade”, 400 )
                elseif 2 == i then
                    – Do nothing; dialog will simply dismiss
                end
            end
        end
        – Show alert with Options. Trigger the wipe action * Return to Menu if the user clicks the 1st button.
        local alert = native.showAlert( “Return to Menu?”, “Are you sure you want to return to the Menu?”,  { “Yes”, “Cancel” }, onComplete )
    
        return true
    end

    local menuButton = widget.newButton{
            left = configPanel.x+87,
            top = configPanel.y-85,
            default = guiImages…“buttonMenuOff.png”,
            over = guiImages…“buttonMenuOn.png”,
            onRelease = goMenu
            }   

[/lua]

Well why #2 works flawlessly on iOS but not Android?
 

Hello,

Error #2 isn’t coming from the button widget, it’s coming from “slider.lua”…

Brent

Here’s the slider.lua code, but I asked for clarification, why does it work on iOS, but not on Android?
[lua]
module( …, package.seeall )

– Slider, created by Microsheep, microsheep.com
– You can see it working in my game - Fingerless 3D
– Free to use, feel free to change, but please share it with the community

– vars
local slider_sprt        = nil
local slides_sprt        = nil
local btns_sprt            = nil

local isDragging        = false
local currSlideIndex    = 1
local startPosX            = 0
local offsetPosX        = 0
local lastPosX            = 0
local lastTimeMsec        = 0
local dX                = 0
local slide_twn            = nil

– forward declerations
local touchCb
local slideEndCb
local toggleBtns
local startDrag
local endDrag
local drag
local slideTo

–##################################################################################################
– PUBLIC METHODS
–##################################################################################################


– init

function init()

    – vars
    slider_sprt        = nil
    slides_sprt        = nil
    btns_sprt        = nil

    isDragging        = false
    currSlideIndex    = 1
    startPosX        = 0
    offsetPosX        = 0
    lastPosX        = 0
    lastTimeMsec    = 0
    dX                = 0
    slide_twn        = nil
    
    – slider_sprt
    slider_sprt = display.newGroup()
    
    – slides_sprt
    slides_sprt = display.newGroup()
    slider_sprt:insert( slides_sprt )
    
    – btns_sprt
    btns_sprt = display.newGroup()
    slider_sprt:insert( btns_sprt )
    
    – events
    slides_sprt:addEventListener( “touch”, touchCb )
    --Runtime:addEventListener( “touch”, touchCb )
    
end


– dispose

function dispose()
    
    – events
    slides_sprt:removeEventListener( “touch”, touchCb )
    --Runtime:removeEventListener( “touch”, touchCb )
    
    – cancel tween
    if ( slide_twn ~= nil ) then
        transition.cancel( slide_twn )
        slide_twn = nil
    end
    
    – btns_sprt
    local thisBtn = nil
    while ( btns_sprt.numChildren > 0 ) do
        thisBtn = btns_sprt[1]
        for j=1, thisBtn.numChildren do
            thisBtn:remove( 1 )
        end
        thisBtn:removeEventListener( “tap”,  tapCb)
        btns_sprt:remove( thisBtn )
    end
    slider_sprt:remove( btns_sprt )
    btns_sprt = nil
    
    – slides_sprt
    slides_sprt = display.newGroup()
    
    local thisSlide_sprt = nil
    while ( slides_sprt.numChildren > 0 ) do
        --thisSlide_sprt.dispose()
        thisSlide_sprt = slides_sprt[1]
        slides_sprt:remove( thisSlide_sprt )
    end
    slider_sprt:remove( slides_sprt )
    slides_sprt = nil
    
    – slider_sprt
    
    – vars

end


– getSprite

function getSprite()

    return slider_sprt
    
end


– getSlide

function getSlide( slideIndex )

    return slides_sprt[slideIndex]
    
end


– setState

function addSlide( slide_sprt, btn_sprt )
    
    – slide
    slides_sprt:insert( slide_sprt )
    slide_sprt.x = (slides_sprt.numChildren - 1) * display.contentWidth
    
    – btn
    if ( btn_sprt ~= nil ) then
        btns_sprt:insert( btn_sprt )
        btn_sprt:addEventListener( “tap”,  tapCb)
        toggleBtns( 1 )
    end
    
end

–##################################################################################################
– PRIVATE METHODS
–##################################################################################################


– touchCb

function touchCb( evt )
    
    if (evt.phase == “began”) then
        startDrag( evt )
    elseif (evt.phase == “ended”) then
        endDrag( evt )
    else
        drag( evt )
    end
    
end


– slideEndCb

function slideEndCb( evt )
    
    – currSlideIndex
    currSlideIndex = 1 + math.floor( (-slides_sprt.x + 0.5 * display.contentWidth) / display.contentWidth )
    – offsetPosX
    offsetPosX = slides_sprt.x
    – btns
    toggleBtns( currSlideIndex )
    
end


– tapCb

function tapCb( evt )
    
    local btnId = evt.target.id
    --toggleBtns( btnId )
    slideTo( btnId, 2500 )
    
end


– toggleBtns

function toggleBtns( activeBtnId )    
    
    local this_btn = nil
    local isActive = false
    for i=1, btns_sprt.numChildren do
        this_btn = btns_sprt[i]
        if ( this_btn ~= nil ) then
            isActive = ( i == activeBtnId )
            this_btn[1].isVisible = isActive
            this_btn[2].isVisible = not isActive
        end
    end
    
end


– startDrag

function startDrag( evt )
    
    isDragging = true
    
    – startPosX
    --startPosX = evt.xStart
    startPosX = evt.x
    
    – offsetPosX
    offsetPosX = slides_sprt.x
    
    – lastPosX and lastTimeMsec
    lastPosX = evt.x
    lastTimeMsec = system.getTimer()
    
    – cancel tween
    if ( slide_twn ~= nil ) then
        transition.cancel( slide_twn )
        slide_twn = nil
    end
    
end


– endDrag

function endDrag( evt )
    
    isDragging = false
    
    – calc speed
    local dT = system.getTimer() - lastTimeMsec
    if (dT < 10) then dT = 10 end
    local speed = dX / ( 0.001 * dT )
    
    – targetSlideIndex
    local targetSlideIndex = currSlideIndex
    
    if (math.abs(speed) > 500) then
        – speed
        targetSlideIndex = targetSlideIndex - (speed / math.abs(speed))
    else
        targetSlideIndex = 1 + math.floor( (-slides_sprt.x + 0.5 * display.contentWidth) / display.contentWidth )
        speed = 1000
    end
    
    – min / max slide index
    if ( targetSlideIndex <= 0 or targetSlideIndex >  slides_sprt.numChildren) then
        targetSlideIndex = currSlideIndex
        speed = 1000
    end
    
    – slide tween
    slideTo( targetSlideIndex, speed )
    
end


– drag

function drag( evt )
    
    if ( false == isDragging ) then
        startDrag( evt )
        startPosX = evt.x
    end
    
    – lastPosX and lastTimeMsec
    dX = evt.x - lastPosX
    lastPosX = evt.x
    lastTimeMsec = system.getTimer()
    
    – pos
    --slides_sprt.x = offsetPosX + evt.x - evt.xStart
    slides_sprt.x = offsetPosX + evt.x - startPosX
    
end


– slideTo

function slideTo( targetSlideIndex, speed )
    
    – cancel tween
    if ( slide_twn ~= nil ) then
        transition.cancel( slide_twn )
        slide_twn = nil
    end
    
    – tween
    local targetPosX = (targetSlideIndex - 1) * display.contentWidth
    local timeMsec = 1000 * math.abs( (slides_sprt.x + targetPosX) / speed )
    --slide_twn = transition.to( slides_sprt, { x = -targetPosX, time = timeMsec, transition = easing.inOutQuad, onComplete = slideEndCb } )
    slide_twn = transition.to( slides_sprt, { x = -targetPosX, time = timeMsec, onComplete = slideEndCb } )
    
end
[/lua]

Hi @waelisnothing,

I don’t really know why it would fail on Android but not iOS, unless there’s some issue with your “module( …, package.seeall )” inclusion. This should not be used any longer, as it was long ago deprecated in Lua.

Brent