eventListener error on changing scene

Hi,

I am using composer and an invisible layer in each scene to detect touch and swipe to change the scene. It works fine unless sometimes I swipe very fast in between scenes and one of these make the app crash (on simulator and device), I get a black screen sometimes with no error returned and sometimes I get this error:

 attempt to call method ‘addEventListener’ (a nil value):

referred to the line where I put the listener on the layer that detect the swipes:

local swipeLayer = display.newRect( centerX, centerY, display.contentWidth, display.contentHeight ) &nbsp;&nbsp;&nbsp; swipeLayer.alpha=0 &nbsp;&nbsp;&nbsp; swipeLayer.isHitTestable = true &nbsp;&nbsp;&nbsp; sceneGroup:insert( swipeLayer ) &nbsp;&nbsp;&nbsp; local function startDrag(event) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local swipeLength = math.abs(event.x - event.xStart) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local t = event.target &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local phase = event.phase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if "began" == phase then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; native.setKeyboardFocus( nil ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif "moved" == phase then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif "ended" == phase or "cancelled" == phase then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if event.xStart \> event.x and swipeLength \> 50 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer.gotoScene("counter",{ effect= "dismissSceneToLeft", time=200}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif event.xStart \< event.x and swipeLength \> 50 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp; end &nbsp;local function sensitizeLayer () &nbsp;&nbsp;&nbsp; swipeLayer:addEventListener("touch", startDrag) -- error returned here &nbsp; end &nbsp;timer.performWithDelay(400, sensitizeLayer)

I also delay the declaration of the event listener to make sure the layer doens’t receive touches during transition but this doesn’t seem to work.

Any idea why this is happening?

Thanks!!!