Flash Player

With Chrome 21 Stable Windows Users Get PPAPI Flash – Comparing PPAPI Flash To Firefox Flash Sandbox

With Chrome 21 Stable Windows Users Get PPAPI Flash – Comparing PPAPI Flash To Firefox Flash Sandbox.

Very clear post on what’s going on with the new PPAPI on chrome and good comparison with firefox.

Here’s also a whitepaper IBM published on this topicΒ https://media.blackhat.com/bh-us-12/Briefings/Sabanal/BH_US_12_Sabanal_Digging_Deep_WP.pdf

enjoy πŸ˜‰

Advertisements
ActionScript 3, AIR, Flash Player

Light on BitmapData memory allocation

Recently at the office we’ve been dealing with a strange BitmapData memory occupation behavior I want to share with you guys.

On this subject the AS3 reference reads “A BitmapData object contains an array of pixel data. This data can represent either a fully opaque bitmap or a transparent bitmap that contains alpha channel data. Either type of BitmapData object is stored as a buffer of 32-bit integers. Each 32-bit integer determines the properties of a single pixel in the bitmap.”

This should be meaning that a BitmapData object should be represented in memory as a sequence of 32 bits integers, one for each pixel in the bitmap, hence width*height*4 bytes which definitely makes sense.
However the actual behavior is significantly different and you can easily find out that the real BitmapData size in memory is not proportional to its area as it should be.
Let’s see an example (code shared at wonderfl)

BitmapData Memory Allocation – wonderfl build flash online

The example shows how different the size of a BitmapData is depending on its maximum dimension: the code instantiates 4096 images with an increasing area from 1 up to 4096 pixels, first with a horizontal extension (width is the increasing dimension, blue line in the chart) then with a vertical extension (height is the increasing dimension, red line in the chart).
You can notice that the behaviors of the lines in the chart are very different and the blue line’s Y is increasing only few times whilst the red one’s (vertical bitmap) is increasing much more frequently and is reaching much higher values.
So what’s the real memory representation of a BitmapData? For sure it isn’t a width*height*4 matrix as it should be and it is stricly related to the dimension the BitmapData is extended on.

We worked a bit on this thing at the office (thanx to Matteo Lanzi) and we found out that BitmapData object memory allocator has a strange behavior: it allocates N chunks of memory aligned to 256bytes (64 pixels) at time.
This would be a useful behavior if the BitmapData object would be resizable via actionscript, but it is not, or if the freed chunks were put in a memory pool and used by the next BitmapData requiring memory, but it doesn’t seem to do that ( the only case we noticed that the memory is reused is when a NxM BitmapData is created, deleted and recreated with the same N and M dimensions ).
If it was only this however it wouldn’t have been such a big problem to deal with, the real big issue is that a 256b chunk is representing a sequence of pixels with a defined horizontal orientation.
This hardcoded behavior leads to a very unpleasant side effect: a BitmapData instance with a high number of little rows (high height, little width,, hence a ‘vertical’ orientation) is occupying a HUGE AMOUNT OF MEMORY while it should be occupying the same memory of a bitmap with the same area rotated by 90Β°.
Let’s seesome more example just to clear out the problem:

Case 1:
– width 1px
– height 1px
– expected allocation: 4 bytes
– actual allocation: 256 bytes (minimum chunk)

a 1×1 px BitmapData allocates in the heap 1 chunk of 256 bytes while only 4 bytes would be needed!! 63x overhead!!!

Case 2:
– width 64px
– height 1px
– expected allocation: 256 bytes
– actual allocation: 256 bytes (fits exactly the minimum chunk)

the same 256 bytes are allocated by a 64×1 bitmap and the overhead disappears, what does happen with a 65×1 one?

Case 3:
– width 65px
– height 1px
– expected allocation: 260 bytes
– actual allocation: 512 bytes (2 chunks)

with a ‘max chunk size plus one’ size a 65 px wide image allocates 2 chunks, the overhead is set to approx 1.9x.

Case 4
– width 1px
– height 64px
– expected allocation: 256 bytes (same area of the 64×1 one…)
– actual allocation: 16 Kb!!!!!

this is the worst case, every in 1xN bitmaps have the maximum overhead possible: 63x!
So try to think about an image very narrow and high, let’s say a 1×4096 one: you would expect it to be 16kb in memory (4096*4 bytes) but it actually is 1 whole megabyte (4096*4*256!!)!!

So, the formula to calculate the ACTUAL memory allocated by a BitmapData expressed in bytes I came up with is:

Math.max( 1 , height*(width/64)>>0 )*256

You can see a more detailed and complete dataset in this google spreadsheet http://bit.ly/FlashBitmapDataAllocation (feel free to spread the link) containing data for BitmapData memory occupation from 1×1 to 1×4096 and from 1×1 to 4096×1.
The test to reproduce the dataset is available on github at this url https://github.com/pigiuz/Tests/blob/master/src/BitmapDataMemoryAllocation.as (feel free to share this link as well)

This behavior has been tested in AIR 3.1 for Mac OSX 10.6 (snow leopard), 10.7 (lion) (thanx to Marco Nava for testing on lion), Window 7, Android 4.0, iOS 5 (thanx to Shawn Blais for testing on mobile),
Flash Player 11,1 by yourself (if you ran the swf linked backward in the post and noticed the same behavior).

After figuring out the problem we opened a bug in adobe’s jira, if you have comments which can raise the attention of adobe on this stuff or add something to the discussion please feel free to comment at this url https://bugbase.adobe.com/index.cfm?event=bug&id=3094186 (you’re welcome to comment here too btw :D)

Few more points worth some attention:
I tried to measure the memory in 3 ways:
– the data got back from flash.sampler.getSize() was not accurate, most of the time it was totally wrong and not predictable (or perhaps I didn’t get how it works in relation with BitmapData objects)
– the delta calculated with a pre and post sampling of System.privateMemory is more accurate than getSize() and fits the expected results in AIR but it’s not as accurate as I expected: in the spreadsheet linked backwards you can see that the results have a coherent trend, but there’s a lot of garbage data and little bitmaps weren’t detected at all.
– the delta calculated witn a pre and post sampling of System.totalMemory is more accurate than System.privateMemory only in flash player.

 

That said,
I find this allocation behavior weird, and the worst thing is that it UNDOCUMENTED and the docs are saying a different thing. I see one VERY significant bad side effects in this way of allocating bitmaps memory that involve how BitmapData objects are stricly tied to the Flash Player’s and AIR runtime’s APIs:
flash.display.Loader generates BitmapData instances when it loads images from URL or streams, so if an application needs to load many bitmaps that don’t fit the memory alignment there will possibly be a HUGE memory waste.
A possible solution could be the creation of few additional functions such as

loadInto(urlrequest:URLRequest, destination:ByteArray):void

and

loadBytesInto(bytes:ByteArray,destination:ByteArray):void

which both take a data source and a preallocated bytearray as input and put outputs to the preallocated bytearray called destination.

 

This is the first shot, I’d really like you guys to spread the word and help me to make adobe sensible on this topic as it’s really worth some effort to make flash and air runtimes even better than what they are now.

Thank you all in advance,
ciao,

pigiuz

ActionScript 3, Flash Player, Flash Player 10

BitmapData and Stage size limit

Short tips post πŸ™‚

BitmapData size limit:
Up to flash 9 the size limit for a BitmapData object was 4096×4096 pixels.
With flash player 10 that limit was removed, but what does this exactly mean? May we be able to create 4097×4097 sized bitmapdata instances? the answer is NO, we can’t.
I just found an official explanation of that here http://kb2.adobe.com/cps/496/cpsid_49662.html

Just in case you don’t have the timewill to read it:
– we still have a limit!
– the limit is set to the maximum amount of pixels (16,777,215 (the decimal equivalent of 0xFFFFFF))
– the maximum valid size of the bounding rectangle side is 8191

Stage size limit:
It actually depends on the stage quality.
With a high quality set the bound limit is 4050×4050, if your content exceeds it gets cropped.
With a low or medium quality the bound limit increases, there’s no official documentation about that (or at least I didn’t find it).
Note that Adobe’s saying that “graphic artifacts” could be displayed when our stage “approaches” 3840 pixels range.

have fun πŸ™‚

Flash Player, Tools, Tutorials

Trace on a shell

Since it has been created i’ve been a fan of flash tracer extension, i really fell in love with that tool, but i noticed it slow down the browser and can even make it crash.

So, let’s open a trace logger on our terminal…

To do that the right command is “tail” which actually “[…]PrintΒ  theΒ  last 10 lines of each FILE to standard output[…]” and the file to open is located in /Users/[your username]/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt

Then, let’s do something good and useful with that:

open your TextEdit, cmd+shift+T to switch to plain text, write down this one line command:

tail -f /Users/[your username]/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt

save the file as “flashtracer.sh” and use sh as file extension instead of txt.

then right click on the file, reach the “open with” menu and choose “terminal” application located inside utility folder. Note: it would be great if you set terminal as default application to open that file πŸ™‚

ok, now everything’s ready; double click on flashtracer.sh and start tracing πŸ™‚

Note: remember you’re in a shell now, so you can clear up the lines with cmd+K…

I hope it can be useful,

byez πŸ™‚

3D, ActionScript 3, Flash Player

Flash 3D stress tests

I just moved to my fresh new country  and started studing for my new job πŸ™‚

I’m trying to get a usual “virtual world” scene (such as second life’s) using (possibly free and open) as3 3D frameworks, so my first choice has been papervision3D.

Unfortunately I’m not a 3D modeler so I had to get models from the web, anyway google sketchup warehouse is a very good resource to collect DAEs (but remember they may be not parsable by ascollada).
For the human model I’ve just “stolen” a walking girl from 3Dflasho.
…and here‘s what I got combining the 2 models: a girl walking in a stadium. (girl is automatically walking forward, just use left and right arrows to make her turn)

pv3dstadium.jpg

(note: textures are about 7 mb and the whole swf is very cpu intensive) 

Take a look to the profiler, you can notice that framerate is very low even on a very good machine (i had a value range from 12 to 18 with everything loaded and 2628 for the girl only on a macbookpro 2.4ghz and flash player 9.0.124 debug).

Next steps for me are:

1) try the same models on Away3D and maybe on Alternativa

2) search for better models (expecially for the stadium which generates too many culling issues on the ground)

3) have a mana potion

I hope to get good news from papervision and away3d mailing lists about flash 10 implementations, expecially about both engines’ drawing speed..in the while I’m going on with my tests πŸ˜€

ActionScript 3, Flash Player

PrintJob bug on OS X 10.5 Leopard

I accidentally found a bug on PrintJob Class on Mac OS X 10.5 (leopard) using Flash Player 9 (i tried every player 9 release up to 124)

printjobbug.png

This the fact:
whenever you try to print something using PrintJob.send() you’ll get a blank sheet instead of the effective Sprite printout.

On previous versions of OS X and on Windows everything is working fine.

Try to test it using Language Reference’s example. It seems not to be working even on AS2 swfs.

I just submitted this bug at bugs.adobe.com, if you have access to serverside scripting AlivePDF project can be a good workaround.
If you find any workaround or want to contribute to solve this issue, here’s the link at adobe bugs: https://bugs.adobe.com/jira/browse/FP-307

Flash Player

FlashLog.txt not being generated on OSX Leopard

I had this nasty problem on my leopard box. I installed flash tracer extension for firefox but nothing was displaied in…

Normally every traced line is written into flashlog.txt file…but actually no flashlog file was being generated! so problem wasn’t on that usefull extension but in flashplayer configuration.

So, here’s the solution i found out:
look for “mm.cfg” file into /Library/Application Support/Macromedia,
then open it with a text editor and write these two lines:

ErrorReportingEnable=1
TraceOutputFileEnable=1

Then save and restart flash player ( just restart your browser…).. Magically flashlog.txt is now being generated and flashtracer start working fine πŸ˜€

NOTE: if you don’t find any mm.cfg file just create it with your text editor and put those 2 lines in it πŸ™‚