Two Times Would Be the Charm
Wednesday, February 22, 2006, at 05:00PM
By Eric Richardson
When I was first learning how to program for modperl I remember hitting the weirdest errors and thinking the application was out to get me. I mentioned that here many times. Usually the problem ended up having to do with me failing to account for persistence. When things stay in memory between runs, you have to be super-thorough to not make a mess with global variables and such cruft like that.
Today I'm having the same sort of issues, but with Flash. When using our app on IE it would appear that it works perfectly the first time, but if you reload it hangs up and eventually you get a message saying that the script is taking too long, would you like to kill it?
Update (1:45am): Found the cause and a solution, so I'm happy.
Now, this is puzzling. Particularly because there shouldn't be any sort of persistence happening here. Reload should be wiping the slate clean and re-instantiating the Flash app. But obviously it's not.
The freeze happens in exactly the same place every time (at least according to my debug messages). There's enough async stuff happening that it's tough to determine exactly where it is when things stop going. I've got it down to about 1/3 of the app, but haven't gotten any closer than that in about eight hours of debugging.
So weird.
I really want to figure this out tonight. If I do I'll sleep in and come in mid-morning feeling good about myself. If not, well, tomorrow might just be another late night in the office.
Update (1am): Turns out what's causing Flash to go haywire is some data that I'm loading in via javascript and passing over to Flash. Commenting out the call to proxy that data over to Flash the app reloads cleanly on IE. Now I just have to figure out if it's an issue in my JS (unlikely) or in the proxy process. Since Flash is crap at loading in external data itself, I need to figure out how to get this to work.
(1:20am): Ok, so here's the Javascript function that's killing me:
function callForBuildingNames() {
fo.call(
'addNamesAndLookups',
buildings.getNames(),
lookups.getMap()
);
}
On initial load in IE both are working fine. On the reload in IE, though, names shows up undefined while the lookups map is correct.
Async is once again the culprit here. The buildings object is pulling JSON data from Rails via the database. The lookups object is pulling JSON data from a flat file. Even though the Rails call only takes something like 1/40 of a second, on reload getNames() is getting called before the object has instantiated its data.
I have no clue why the Flash is hanging if the names don't show up. Now that I know where to check for not having data, though, I should be able to catch the issue and try again.
(1:45am): The code on the ActionScript side now does:
function addNamesAndLookups(names:String,lmap:String) {
if (names && lmap) {
// do our stuff
} else {
if (this.retries < 3)
_global.setTimeout(function() {
_global.proxy.call('callForBuildingNames')
},500);
this.retries++;
}
}
}
That seems to please everyone. Though just as easily I could do the timeout on the javascript side and just hang a little before sending the data over to Flash (which isn't waiting on it).