Showing posts with label ActionScript. Show all posts
Showing posts with label ActionScript. Show all posts

Sunday, January 11, 2009

AIR String concatenation bug

Well the other day I was doing some file IO to tidy up some CSV files. I was trying to do this quickly and just was using a String to stored the data before writing it to file. I'm sure your thinking I should be using stream for this and I would agree with you. But at the time I didn't believe there would be an issue with the data size. Then I found my fairly simple AIR app crashing quite badly. OS X kill the app because of the following error.

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
Crashed Thread: 0

As you can see this is far from nice and most importantly this is a operating system error not a native AIR/AS3 error. So what is causing this fatal error? Well just concanate two large strings you will get this. I created a dummy programme to show the issue.

var myStr:String = new String("1");
for ( var i:int = 0; i < 100; i++) {
myStr = myStr + myStr;
}


On my machine it completed to the 29th loop before failing. So it could handle 2^29 but no larger.

Can you protect your app from this with a try/catch statement? No. This is a real pain in the neck. It's not like I'm writing the app in C/C++ where you can drive your app into the wall because you the developer are managing memory. With ActionScript I would expect the Flash player/runtime to return an error and not crash since it is managing memory.

I will add this as a bug or vote for this fix if it is already entered.

Monday, June 2, 2008

Flex Inline function & Flex Cookbook

It's cool to see a Flex Cookbook out there for new coders to leverage knowledge and skills of more experiences developers.

I was a bit surprised by the top rated recipe How to Pass Additional parameters to event listener using ActionScript for reason it uses an inline function to add additional information to standard event. I do think this is an innovative way of passing additional data. After saying that I don't think it is away I would recommend to any developer to use. Since it goes against good programmer practices of creating maintainable code. Key reason is that you have no way of removing this function from an event listener (unless you do another hack to get it's name at runtime). The second key reason why I think this is bad practice is that creating your own event is just as easy. So I don't see any major benefit other than obfuscating the code.

Thursday, May 22, 2008

Things I didn't know...

I was coding away and found myself with the need to pass a reference to a function in ActionScript in an event.  Well it is easy as :-)  All you do is add a variable of type Function to your event hay presto you can do it.  It sort feels like a GOTO statement since your calling a function out of context.  I know a lot of languages can do this and have done it myself with other languages but was a first time with ActionScript today.

Oh don't forget about Flash Player 10 it's in beta now!  Got lots of cool new features ~ though I'm looking forward to seeing what can be done with the new Advance Text Layout and Custom Filters and Effects after finding the limits with the current release 9.

Countdown to WebDU is on now!  Less than three weeks to go...