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: [C]: ? ?: in function '?' ?: in function \<?:467\> ?: in function \<?:218\>
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.