Sorry to report that the problem IS with something that you changed in v1.2. If I use my modified 1.1 Director code, then I don’t get the hang/crash on the actual phone. But using 1.2 I do.
I’ve been spending the afternoon trying to track down the problem. I have 4 changes that seem to help:
- First, in my modified code, I am saving each timer.performWithDelay result and then testing that in director:changeScene. You are just checking the “isChangingScene” variable instead and returning.
This means the user cannot interrupt a transition in progress. I do not believe this is good behavior. If the user taps the screen before the previous transition is complete, you shouldn’t just ignore them. You should cancel the previous effect and execute the new transition. So instead of your code:
[lua] if isChangingScene then
return true
else
isChangingScene = true
end[/lua]
I have this:
[lua] if (directorTimer) then
– ensure that we don’t change again until previous transition is finished
timer.cancel( directorTimer);
fxEnded();
end[/lua]
where “directorTimer” is the result of any previous timer.performWithDelay call.
Also set
[lua]directorTimer = nil[/lua] near the end of the fxEnded() routine.
-
Next, you check to see if the current scene is the same or not. I ran into trouble with this. It was still preventing me from interrupting current transitions. I think it is because of where “currScene” is set vs the old code that had “lastScene”. So I changed your code
[lua] if currScene then
if string.lower(currScene) == string.lower(nextLoadScene) then
return true
end
end[/lua]
back to this
[lua] if lastScene then
if string.lower(lastScene) == string.lower(nextLoadScene) then
return true
end
end[/lua]
and near the bottom of this routine before the return, I added:
[lua] lastScene = nextLoadScene[/lua]
-
The new unloadScene() routine seems to be causing problems. The more extra display objects you have on the screen, the more noticeable the issue is. With the above two changes, you can tap between two scenes really quickly to debug and uncover additional issues. Without the above changes you are forcing the user to wait until transitions are complete, which hides these additional timing issues that cause the actual phone devices to crash/exit (because of timing differences with the simulator).
If I comment out the call to
[lua]unloadScene( currScene)[/lua]
in fxEnded() then it removes a lot of the crash issues.
- In addition to the above, I’m not sure about the changes to the loadScene() routine. Instead of just creating the new screen with “require(moduleName).new()” as in v1.1, now you have a bunch of additional code that calls “callClean()” and “cleanGroups()” and “unloadScene()”. Seems like this is duplicating what is in the fxEnded code. I think this extra code is causing some resources to be freed prematurely, which causes the actual phone devices to crash.
If I remove any of these 4 changes, then I get crashes on the actual phone. I think (1) and (2) just make it easier to reproduce the real problem by allowing fast transition interruptions. But the root cause is somewhere in how resources are being freed and garbage is being collected. I just can’t track down the actual cause.
In general I think it is a bad idea to force a call to collectgarbage yourself. This should be left up to the operating system. But it’s also possible that collectgarbage is just showing the problem because something has been freed that shouldn’t be.
I will let you look at your own code more to try and figure it out. I need to get on with my own app development and for now I’m just going to use the above changes since they seem to work. Good luck with this, and be sure to test on real hardware. There definitely is some differences between the simulator and actual hardware in these issues. [import]uid: 12529 topic_id: 6676 reply_id: 23342[/import]