Not sure how to name this issue. But overlay crash upon hiding.

Sorry I can’t put a better title. I am not sure if this is a bug or intentional so I am posting here.

I have an event that dispatch to all storyboard scene if they are active (overlays) when my pet dies. Currently opened overlay will listen to the event and then hides itself (hideOverlay). 

Here is the problem, when I am holding down a button when this event is dispatch, it will hide the overlay normally. However once I release the mouse, a segmented error is given in the terminal. I have this error before when I accidentally detected touch event without checking for touch phase when hiding the overlay.

The above problem is solved by adding before hiding the overlay:

display.getCurrentStage():setFocus( nil )

this is to cancel out any scrollers or buttons or other things that is taking focus. 

I am not sure if this is a bug or intentional so I am just posting it here. The version I am using is 1137.

Hi Jeffrey,

Are you closing these using a regular touch handler, or via a dispatch using “dispatchEvent()” call?

Brent

Hello,

I am closing it via dispatching a custom event:

gamespace:dispatchEvent( { name = “forceclose” } )

Hi Jeffrey,

That helps explain the probable issue. When you dispatch an event using that API (like a “touch” that’s not a physical touch), you also need to dispatch the “phase” too, just like an actual screen touch would have. So, something like this:

[lua]

myObject:dispatchEvent( { name=“touch”, phase=“began”, x=event.x } )

[/lua]

Please review the docs on the dispatch call carefully, as this is a common stumbling block when using it:

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Brent

Ok i manage to reproduce it. Using the default button will not have any issues or produce any segmented errors. But using a custom image (defaultfile and overfile) will cause the segmented error.

Steps to reproduce:

  1. Run the file in corona simulator 1137 (stable version)

  2. Press the open overlay button, when in the overlay, hold down the blue “X” button until overlay is closed.

  3. The game.lua will countdown 5 seconds and then dispatch an event to overlay to close it.

  4. While the X button is hold down and the event dispatched to close it, it will crash the simulator.

**Please note that if the button in the overlay doesn’t have a custom image, it will not crash.

Download the file attached.

Hi Jeffrey,

Are you closing these using a regular touch handler, or via a dispatch using “dispatchEvent()” call?

Brent

Hello,

I am closing it via dispatching a custom event:

gamespace:dispatchEvent( { name = “forceclose” } )

Hi Jeffrey,

That helps explain the probable issue. When you dispatch an event using that API (like a “touch” that’s not a physical touch), you also need to dispatch the “phase” too, just like an actual screen touch would have. So, something like this:

[lua]

myObject:dispatchEvent( { name=“touch”, phase=“began”, x=event.x } )

[/lua]

Please review the docs on the dispatch call carefully, as this is a common stumbling block when using it:

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Brent

Ok i manage to reproduce it. Using the default button will not have any issues or produce any segmented errors. But using a custom image (defaultfile and overfile) will cause the segmented error.

Steps to reproduce:

  1. Run the file in corona simulator 1137 (stable version)

  2. Press the open overlay button, when in the overlay, hold down the blue “X” button until overlay is closed.

  3. The game.lua will countdown 5 seconds and then dispatch an event to overlay to close it.

  4. While the X button is hold down and the event dispatched to close it, it will crash the simulator.

**Please note that if the button in the overlay doesn’t have a custom image, it will not crash.

Download the file attached.