Transitions 2.0 callbacks may end out of context

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.

Hi @tntwickey,

It appears that this issue was resolved in Build #1243. Can you please download it and test your scenario?

Thanks,

Brent

Thanks Brent. I saw the changelog that mentioned transitions and tried it without luck.

I am on currently on 1247 and it’s still broken.

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.

Anything? Should I file a bug report? How can we get this resolved?

Bug was submitted long time ago: 

26812

Hey guys,

I really thought that got fixed through the last update.

Looking at it now.

alex

Hey alexf. Any progress?

Alexf and whomever is working on this:

Try this:

local trans1,trans2=nil,nil local d = display.newRect(50, 50, 100, 100) local d2 = display.newRect(150, 50, 50, 50) trans1 = transition.to(d, {time = 1000, x = 50, y = 150}) trans2 = transition.to(d2, {time = 1000, x = 50, y = 350}) timer.performWithDelay(2000, function() transition.cancel(trans1) transition.cancel(trans2) trans1 = transition.to(d, {time = 1000, x = 50, y = 150})--does not move trans2 = transition.to(d2, {time = 1000, x = 150, y = 50}) end, 1)

Line 12 does not animate. This is one of the issues I am seeing. Trying to isolate all of them.

tntwickey, i am. I fixed it, testing regression now.

alex

Today’s build? I keep hoping

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 have the original issue with build 1256. This is with a transition that is cancelled but the onComplete still fires. Was this fixed in last few builds?

attempt to index field '?' (a nil value) stack traceback: [C]: ? ?: in function '?' ?: in function \<?:467\> ?: in function \<?:218\>

Seriously, when is this going to be fixed? Is there anything we can do to speed it along?