bitmapdata.lock error

Asked by Adam Holland

Hi, I just downloaded the latest version and I get an error when I lock() a bitmapdata and the call its copyPixels() method. I can run teh code without the lock() but it is very slow compared to the flash compiled version.

I see Jeash has a drawToSurface, should i actually be using this instead of the copypixels? I am running a benchmark to see what sort of performance I get (Bunnymark :)) In flash I can get 10000 + but in HTML i can even get 300 at 30fps.

Thanks,

Adam

Question information

Language:
English Edit question
Status:
Solved
For:
jeash Edit question
Assignee:
No assignee Edit question
Solved by:
Adam Holland
Solved:
Last query:
Last reply:
Revision history for this message
Niel Drummond (niel-drummond) said :
#1

If you want good performance in jeash, you should be caching your bitmaps and avoid bitmapdata - bitmapdata is good for low-level access to pixel data, but this is slow if you are calling copypixels for every frame.

Create a Bunny in separate Bitmaps and move their x and y co-ordinates. Although this creates overhead with the number of objects, it will also create separate canvas tags in the HTML, and if you have a good browser and OS, these tags will benefit from GPU acceleration.

Revision history for this message
Adam Holland (adgholland) said :
#2

Hey, thanks for the response. I will do some more tests using the display list.

Thanks,

p.s you didn't mention anything about the error.

Revision history for this message
Niel Drummond (niel-drummond) said :
#3

Was there an error message or did it simply timeout ?

In the development version, if the bitmapdata is locked, copyPixels is done completely in software pixel-by-pixel, which has the best compatibility with flash but is not useful in most cases. If the bitmapdata is not locked, copyPixels will ignore some arguments and use a straight canvas drawImage onto the target HTML canvas.

I was not sure whether to leave the software mode in, it's possible that I will pull it out for the next release.

Revision history for this message
Adam Holland (adgholland) said :
#4

Hi,

Yes it throws an error on each loop: http://dl.dropbox.com/u/698268/error.png. Here is the code for my update:

                        canvasData.lock();
   canvasData.fillRect(rect, 0xFFFFFF);
   for (i in 0...numBunnies)
   {
    var b:Bunny = bunnyArr[i];
    b.update();
    b.render(canvasData);

   }
   canvasData.unlock();

The render method of the Bunny class:

        public function render(canvasData:BitmapData):Void
 {
  dest.x = x;
  dest.y = y;
  canvasData.copyPixels(imageData, rect, dest, null, null, true);
 }

If i comment out the lock() it runs.

I am very new to Haxe and do not have any recent knowledge of Javascript unfortunately. I am just testing the different outputs and also using NME.

I would say I think you should leave a software option however. I work for a small indie game company and some of our games are for clients. With such variying results when using Hardware, it is often safer just to use software.

Thanks for you help.

Revision history for this message
Niel Drummond (niel-drummond) said :
#5

I looked at the code again, it seems I never committed the software mode, though I did find some other issues so I have reverted some parts of the code back to 0.8.5..

sorry, but jeash still must make a good balance between flash compatibility and performance..

right now locked and unlocked copypixels works identically.

Revision history for this message
Adam Holland (adgholland) said :
#6

Hey thanks for all your work, as I said im still int he tesing phase but in the future I coudl see myselfe using libs like jeash daily. Thanks again!

Adam