Transitions 2.0 callbacks may end out of context

Hi,

Please scroll down few comments for more info.

this error is thrown on ios, android and simulator:

I/Corona (25899): Runtime error
I/Corona (25899): ?:0: attempt to perform arithmetic on field ‘?’ (a nil value)
I/Corona (25899): stack traceback:
I/Corona (25899): [C]: ?
I/Corona (25899): ?: in function ‘?’
I/Corona (25899): ?: in function <?:467>
I/Corona (25899): ?: in function <?:218>
I/Corona (25899): Runtime error
I/Corona (25899):
I/Corona (25899): stack traceback:
I/Corona (25899): [C]: ?
I/Corona (25899): ?: in function ‘?’
I/Corona (25899): ?: in function <?:467>
I/Corona (25899): ?: in function <?:218>

I’m quite certain this is related to transitions.
Looks like transition onComplete doesn’t even get to my code.
The paste is from Simulator.

 

That’s a bit weird because I have apps that depend on transitions, and they behave correctly with #1228.

The only thing I did to make it work was to revert back to 1216.
I can confirm this error is fired any time I change to 1228.

It’s hard for me to debug since it’s not triggered anywhere within my code, but this is thrown wnever I expect onComplete function to be fired, and it does not start.

Here’s an example on how I run my transitions:

transition.to(portal, { time = 1000, xScale = 0.1, yScale = 0.1, onComplete = removePortal })

nothing fancy!

I forgot one of the most important things in my original post: this error is thrown quite random.
I was able to test my apps fine and release updates, before I got first reports that something is wrong. Only after spending some more time I was able to get this in my logs.

Hi krystian6,

Could you please post a bit more complete example? Like what type of object is portal, and what properties do you set on it before creating the transition? From your pasted code, if i put that in a testbed in 1228 it works, as ingemar also stated above…

Thanks,

Alex

I just had a look through my code and I use quite a lot of transition.to() and transition.from() calls with onComplete blocks, and all of them are functioning properly when I run my tests…

However you say that it’s intermittent, and you’ve noticed the problem only after spending some time with the code.

Could you elaborate more on how much time was needed for you to notice a problem yourself? 

Hi guys,

sorry to keep you waiting. I went through this case as it was extremely weird.

If you want to skip my elaborate on what is happening, I’ll just let you know, that I thought Transitions 2.0 were introduced in an earlier version than I have used, but it was actually one later. So all of my tests before 1228 were conducted on Transitions 1.0

I’ve got few testing environments, and same version of the code behave differently on one than on the others. Pain.

Anyway, I’ve been able to find a spot within my game, where I hit the problem all of the time. So you know: I use transitions all the time, within the whole game, in plenty of places. Most of them have onComplete function specified, so this is ran at least 100 times before I get to the spot which causes issues.

I’ve been dealing with this doing an update to Elemental Defender. It’s a game where enemies spawn on top of the screen and you shoot arrows to kill them. Obvious. The first weird thing I have noticed, was that when I killed my enemy, the death animation was played but then the transition of movement began to play again and the last frame of a dead enemy was moving toward the wall. Huh…

Then in other place, in certain specific scenario, one of the shops would not load at all, giving me a lot of errors on screen, all of them with stack traces starting with the same lines as I have pasted.

So back to tracing. I’ve noticed that when onComplete function is called, some of the variables it was meant to use were pointing to different objects. This did not happen all of the time, mind you, so it was not easy to spot, but since lots of my game logic relies on transitions, funny things like the above were happening.

I assume this is my fault, I was able to identify few places where I could use additional local variables to tackle the context issue, but it still is weird that with transitions 1.0 everything worked fine. Another thing is that this issue is intermittent, the same scene which would not load one time, would work fine other time. The issue with enemies happened like 1 time per 100 enemies.

I guess you just have to make sure the variables you use during onComplete call are the ones you actually expect.

Thanks

Krystian

EDIT:

Fun fact: I haven’t touched my code between changing versions of Corona. The only thing I did was remove the sandbox directory. Yesterday I was unable to enter one scene so I reverted to previous version, built the game, ran some tests and released it. Today, since we are going to switch to transitions 2.0 and we are looking for all spots that this error could happen, I’ve updated corona back to 1228, and I am able to get to the same scene without problem. Exact same scenario, exact same code. But worry not, another part of the game, which worked fine yesterday when testing with 1228, today causes error.

EDIT2: I’m a bit tired. I just realized, that although in some cases, there’s a problem with onComplete calls and that they loose their context, there’s another. In case of onComplete errors, I can see the onComplete function call in stack trace, however this stacktrace:

2013-10-08 09:41:34.396 Corona Simulator[2318:e03] Runtime error ?:0: attempt to perform arithmetic on field '?' (a nil value) stack traceback: &nbsp;&nbsp;&nbsp;&nbsp;[C]: ? &nbsp;&nbsp;&nbsp;&nbsp;?: in function '?' &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:467\> &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:218\> &nbsp;

clearly states, that it didn’t even get to my onComplete function to call it. It looks like, transitions 2.0 lost the ability to access the transitioning object.

Wow. That’s a tricky one! 

As mentioned above, my apps also have quite a few transitions. Although I’ve tested my apps with Transitions 2.0, I have yet to release an app with it. I’ll keep an eye out for any weirdness and report back here if I experience similar behaviour.

I think I have found the reason why is this happening.

I believe, Corona folks, messed up the sequence of execution of the code. Something they did some time ago with sprite animations.

Here’s a code which will trigger the error I get:

local d = display.newRect(50, 50, 50, 50) local t = transition.to(d, {time = 10000, x = 50, y = 50, delta = true, onComplete = function() print "whateva" end}) transition.cancel(t) d:removeSelf() d = nil

Do it this way, and you will see a new “feature”

local d = display.newRect(50, 50, 50, 50) local t = transition.to(d, {time = 10000, x = 50, y = 50, delta = true, onComplete = function() print "whateva" end}) transition.cancel(t) timer.performWithDelay(1, function() d:removeSelf() d = nil end)

although I have cancelled the transition, the on complete function gets called!!

The behaviour I would expect only happens with this code:

local d = display.newRect(50, 50, 50, 50) local t = transition.to(d, {time = 10000, x = 50, y = 50, delta = true, onComplete = function() print "whateva" end}) timer.performWithDelay(1, function() transition.cancel(t) d:removeSelf() d = nil end)&nbsp;

It’s like déjà vu. It’s the EXACT same issue as with sprites animation!

I’ve got code full of 1 millisecond transitions to set the correct frame!

Dammit!

I was able to replicate and i’m working on a fix. I’ll update the thread as soon as it’s posted.

alex

I can see why this is happening.

The example code is creating the transition, and cancelling it in the same run-loop.

I suspect that Corona needs at least one frame to “get its act together” internally, that’s why a 1ms delay works.

Any progress on a fix? I will switch back to an old build for the time being.

Any progress on this issue?

Using the new transition 2.0 library I can cancel all transitions, and still get an onComplete from a transition.

How can that be? Can’t count on anything behaving the same.

Hey tntwickey,

There are still two issues when using delta transitions. We’re already testing the fixes internally, so they should be available soon.

alex

I appreciate it alexf. Will the fix turn up in the next daily build? 

That’s a bit weird because I have apps that depend on transitions, and they behave correctly with #1228.

The only thing I did to make it work was to revert back to 1216.
I can confirm this error is fired any time I change to 1228.

It’s hard for me to debug since it’s not triggered anywhere within my code, but this is thrown wnever I expect onComplete function to be fired, and it does not start.

Here’s an example on how I run my transitions:

transition.to(portal, { time = 1000, xScale = 0.1, yScale = 0.1, onComplete = removePortal })

nothing fancy!

I forgot one of the most important things in my original post: this error is thrown quite random.
I was able to test my apps fine and release updates, before I got first reports that something is wrong. Only after spending some more time I was able to get this in my logs.

Hi krystian6,

Could you please post a bit more complete example? Like what type of object is portal, and what properties do you set on it before creating the transition? From your pasted code, if i put that in a testbed in 1228 it works, as ingemar also stated above…

Thanks,

Alex

Any update on this?

I just had a look through my code and I use quite a lot of transition.to() and transition.from() calls with onComplete blocks, and all of them are functioning properly when I run my tests…

However you say that it’s intermittent, and you’ve noticed the problem only after spending some time with the code.

Could you elaborate more on how much time was needed for you to notice a problem yourself?