button release crashes when scene changed automatically

Hi,

I have a main menu which goes into a automatic game mode after a time delay (the game plays itself) 

I noticed that when you have you finger pressed on a button on the main menu and release it during the scene change, the program crashes unexpectedly. Since this is a pretty specific bug I thought I’d post it here. I will try and keep a flag in my event listeners of my buttons that stop my game from going into automatic mode when the player presses and holds a button but I thought I’d mention it here either way since it is a corona bug.

There are too many variables in play here.  How are your buttons defined?  What’s going on in your touch handler?  What runtime events or other onComplete things are going on?

What error are you getting?

Without seeing some code or more specifics on the errors the best anyone can do is guess.

Rob

I can’t reproduce the bug in a small and simple program so it looks like I am causing the crash.

The crash didn’t have a stack trace, the simulator just crashed so it made it hard for me to find out what part of my code is wrong.

I thought it might be a corona issue because in my exitScene I called removeSelf on my button that caused the crash so I wasn’t sure what could still be triggering when releasing the button during the change scene. Trying the same thing in a small test program doesn’t crash the simulator so that’s good news for you :slight_smile:

– main 

local widget = require (“widget”)

local storyboard = require(“storyboard”)

storyboard:gotoScene(“scene1”)

–scene 1

local storyboard = require(“storyboard”)

local widget = require(“widget”)

local scene = storyboard.newScene()

local button = nil

function myManualEvent(event)

    print(event.phase)

    if event.phase == “ended” then

        storyboard:gotoScene(“scene2”)

    end

end

function automaticSceneChange()

    print(“auto”)

    storyboard:gotoScene(“scene2”)

end

function scene:enterScene( event )

    print(“entered scene1”)

    timer.performWithDelay(1000,automaticSceneChange,1)

    button = widget.newButton

    {

        left = display.contentWidth / 2,

        top = display.contentWidth / 2,

        width = 100,

        height = 50,

        onPress =  myManualEvent,

        onRelease = myManualEvent,

        label = “test”,

        fontSize = 10,

    }

     

end

function scene:exitScene( event )

    print(“exited scene1”)

    button:removeSelf()

end

scene:addEventListener( “enterScene”, scene )

scene:addEventListener(“exitScene”, scene)

return scene

– SCENE 2

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

– Called immediately after scene has moved onscreen:

function scene:enterScene( event )

    print(“entered scene2”)

end

function scene:exitScene( event )

    print(“exited scene2”)

end

scene:addEventListener( “enterScene”, scene )

scene:addEventListener(“exitScene”, scene)

return scene

I’ve seen things like this when your apps is calling storyboard.gotoScene() multiple times, for instance if you left the if event.phase == “ended”  out of your button handler, you would call storyboard.gotoScene() multiple times and which case the scene you are leaving would execute it’s exitScene twice deleting a button that’s no longer there on the second pass.  However your if event.phase == “ended” is basically making the onPress do nothing.

However that timer is still going to fire and call storyboard.gotoScene() which if you tap the button before the timer fires, the timer is still active and weird things happen when timers fire and the scene is no longer there, like if you are removing the scene() and the function timer tries to call no longer exists you get a Signal 11 SIGSEGV segment violation error which will crash the simulator and the app on device.

Rob

There are too many variables in play here.  How are your buttons defined?  What’s going on in your touch handler?  What runtime events or other onComplete things are going on?

What error are you getting?

Without seeing some code or more specifics on the errors the best anyone can do is guess.

Rob

I can’t reproduce the bug in a small and simple program so it looks like I am causing the crash.

The crash didn’t have a stack trace, the simulator just crashed so it made it hard for me to find out what part of my code is wrong.

I thought it might be a corona issue because in my exitScene I called removeSelf on my button that caused the crash so I wasn’t sure what could still be triggering when releasing the button during the change scene. Trying the same thing in a small test program doesn’t crash the simulator so that’s good news for you :slight_smile:

– main 

local widget = require (“widget”)

local storyboard = require(“storyboard”)

storyboard:gotoScene(“scene1”)

–scene 1

local storyboard = require(“storyboard”)

local widget = require(“widget”)

local scene = storyboard.newScene()

local button = nil

function myManualEvent(event)

    print(event.phase)

    if event.phase == “ended” then

        storyboard:gotoScene(“scene2”)

    end

end

function automaticSceneChange()

    print(“auto”)

    storyboard:gotoScene(“scene2”)

end

function scene:enterScene( event )

    print(“entered scene1”)

    timer.performWithDelay(1000,automaticSceneChange,1)

    button = widget.newButton

    {

        left = display.contentWidth / 2,

        top = display.contentWidth / 2,

        width = 100,

        height = 50,

        onPress =  myManualEvent,

        onRelease = myManualEvent,

        label = “test”,

        fontSize = 10,

    }

     

end

function scene:exitScene( event )

    print(“exited scene1”)

    button:removeSelf()

end

scene:addEventListener( “enterScene”, scene )

scene:addEventListener(“exitScene”, scene)

return scene

– SCENE 2

local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

– Called immediately after scene has moved onscreen:

function scene:enterScene( event )

    print(“entered scene2”)

end

function scene:exitScene( event )

    print(“exited scene2”)

end

scene:addEventListener( “enterScene”, scene )

scene:addEventListener(“exitScene”, scene)

return scene

I’ve seen things like this when your apps is calling storyboard.gotoScene() multiple times, for instance if you left the if event.phase == “ended”  out of your button handler, you would call storyboard.gotoScene() multiple times and which case the scene you are leaving would execute it’s exitScene twice deleting a button that’s no longer there on the second pass.  However your if event.phase == “ended” is basically making the onPress do nothing.

However that timer is still going to fire and call storyboard.gotoScene() which if you tap the button before the timer fires, the timer is still active and weird things happen when timers fire and the scene is no longer there, like if you are removing the scene() and the function timer tries to call no longer exists you get a Signal 11 SIGSEGV segment violation error which will crash the simulator and the app on device.

Rob