Timer callback preventing object deletion on scene exit?

First off, I’m using the old-style scene editor. don’t know if that has anything to do with the following problem-

I’m creating a graphic and placing it like so-

num2Stargraphics = display.newImageRect("number2/num2\_star.png", 124, 128) num2Stargraphics.x = display.contentWidth/2 num2Stargraphics.y = display.contentHeight\*.2 num2Stargraphics.alpha = 0

When the user touches a separate display object, I make the graphic visible and rotate continuously. This code is inside the “began” phase of a startDrag event on the touched object.

 num2Graphic\_trans = transition.to(num2Stargraphics, {time=2000, alpha = 1})     function star1listener( event )   num2Stargraphics:rotate(5)  end  num2Graphics\_time = timer.performWithDelay( 10, star1listener, 0)

When the scene exits, I’m removing the timers and transitions and setting them to nil, and removing the num2Stargraphics object, like this- (I’ll leave out the transition and timer cancel code, it’s standard as below)

display.remove(num2Stargraphics) num2Stargraphics = nil

When I exit the scene, I get a hangup on the simulator, with an error message stating that num2Stargraphics is a nil object, and it traces the error to the timer function. I can get rid of the error by commenting out various parts of the timer function as follows-

function star1listener( event ) --IF I comment out the rotate   --num2Stargraphics:rotate(5)  end  --OR I comment the timer like this --num2Graphics\_time = timer.performWithDelay( 10, star1listener, 0) --OR I get rid of the timer iteration "0".. --no problem!

Hope that makes sense. To sum it up, if I get rid of any one of those three lines, it works on scene exit. Of course, if I use the display.remove method on the num2Stargraphics object, it also gets rid of the error, but the graphic stays visible in the next scene.

Any help or feedback would be greatly appreciated.

Thanks!

When you say “old-style scene editor” are you referring to Director, Storyboard, or another solution?

I’m going to assume you are talking about Storyboard at this point. Are you declaring your timer, transition and display object variables outside of the scene code? This is essential to cancelling them when exiting the scene. If you can post 1) your code and 2) the console error, it would be easier to tell where the issue exists.

When you say “old-style scene editor” are you referring to Director, Storyboard, or another solution?

I’m going to assume you are talking about Storyboard at this point. Are you declaring your timer, transition and display object variables outside of the scene code? This is essential to cancelling them when exiting the scene. If you can post 1) your code and 2) the console error, it would be easier to tell where the issue exists.