Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411592 Posts in 69386 Topics- by 58444 Members - Latest Member: FightingFoxGame

May 07, 2024, 06:28:00 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)bitMapData.copyPixels issue
Pages: [1]
Print
Author Topic: bitMapData.copyPixels issue  (Read 2399 times)
rejwan
Level 0
**


View Profile
« on: August 05, 2010, 06:25:46 AM »

Hi everyone,

I'm currently working on a hexagon map that will work with blit scrolling, meaning I draw only what is needed plus a small buffer and redraw whenever needed.


Now - Going left and right works perfectly - however, when I try to scroll down, a very peculiar issue occurs.


The map is first copied without the row that was removed from view, and then the new buffer rows are being drawn.


I've isolated the issue to the initial cropping of the photo and found a very unusual bug and was hoping someone here could help me.


Here's the screenshots from my debugs:


bufferBD.copyPixels(bufferBD, new Rectangle(0, 0, bufferBD.width, bufferBD.height), new Point());


bufferBD.copyPixels(bufferBD, new Rectangle(0, 400, bufferBD.width, bufferBD.height), new Point());


Now here the crazy begins, any Y given between (more or less) 0 and 400 causes this issue:

In this sample, HEX_HEIGHT = 87

bufferBD.copyPixels(bufferBD, new Rectangle(0, HEX_HEIGHT, bufferBD.width, bufferBD.height), new Point());


Please help!

Thanks,

Ron
Logged

st33d
Guest
« Reply #1 on: August 05, 2010, 06:47:40 AM »

You're copying from the buffer at some point down it and you've tried to copy the whole height of the buffer. To itself.

copyPixels should be used on the display bitmapData, copying from another bitmapData.

If you copy to the same bitmapData - it's just going to wreck itself!
Logged
rejwan
Level 0
**


View Profile
« Reply #2 on: August 05, 2010, 06:57:19 AM »

That's the thing - by copying itself from left to right or from right to left it works 100%.

Copying from Y 0 or 400 works 100% but in between it gets crazy.

EDIT:
These are the copy left\right codes that work 100%:

Copy left:
bufferBD.copyPixels(bufferBD, new Rectangle(((lastStartHexX + colsPerRow) % 2 == 0 ? -50: -100) * missing, 0, bufferBD.width, bufferBD.height), new Point());

Copy right:
bufferBD.copyPixels(bufferBD, new Rectangle((lastStartHexX % 2 == 0 ? 100 : 50) * missing, 0, bufferBD.width, bufferBD.height), new Point());
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #3 on: August 05, 2010, 12:59:30 PM »

If you copy to the same bitmapData - it's just going to wreck itself!
Actually the docs explicitly allow for this case. And it's correct for rejwan is attempting to do (keep the bitmap still, but give it the illusion of scrolling). However, it still seems likely that this is the source of the problem, you should implement double buffering to be on the safe side.
Logged
rejwan
Level 0
**


View Profile
« Reply #4 on: August 05, 2010, 02:39:12 PM »

I am implementing double buffering on all sides!

And as you can see in the screenshots, copying the bitmapdata to itself works fine when Y is 0 or 400, but in between it copies it choppy.

Really weird one, need help please Sad
Logged

st33d
Guest
« Reply #5 on: August 05, 2010, 02:53:44 PM »

What is the specific height of bufferBD.height?
Logged
rejwan
Level 0
**


View Profile
« Reply #6 on: August 05, 2010, 04:47:57 PM »

What is the specific height of bufferBD.height?

892px
Logged

bateleur
Level 10
*****



View Profile
« Reply #7 on: August 05, 2010, 11:01:12 PM »

OK, having done some proper tests on this it looks like a bug. I've implemented a quick demo on wonder.fl here:

 http://wonderfl.net/c/wObZ

As the copy "distance" decreases, the bug is more likely to occur. Similarly, as the width of the BitmapData used increases, the bug is more likely to occur.

Worse, it seems to be the case that the bug occurs unreliably for some combinations of parameters. I haven't been able to get good test data on that, though, so would welcome verification. Edit: Confirmed - results appear erratic!

Overall, looks pretty bad. Screamy

Edit 2: Suspecting the erratic behaviour might mean that the problem was at the render-to-screen stage I tried a variation in which the resulting Bitmap isn't added to the display list for 100 frames:

 http://wonderfl.net/c/tP6S

...unfortunately it's just as broken.
« Last Edit: August 05, 2010, 11:14:24 PM by bateleur » Logged

rejwan
Level 0
**


View Profile
« Reply #8 on: August 06, 2010, 04:54:05 AM »

OK, having done some proper tests on this it looks like a bug. I've implemented a quick demo on wonder.fl here:

 http://wonderfl.net/c/wObZ

As the copy "distance" decreases, the bug is more likely to occur. Similarly, as the width of the BitmapData used increases, the bug is more likely to occur.

Worse, it seems to be the case that the bug occurs unreliably for some combinations of parameters. I haven't been able to get good test data on that, though, so would welcome verification. Edit: Confirmed - results appear erratic!

Overall, looks pretty bad. Screamy

Edit 2: Suspecting the erratic behaviour might mean that the problem was at the render-to-screen stage I tried a variation in which the resulting Bitmap isn't added to the display list for 100 frames:

 http://wonderfl.net/c/tP6S

...unfortunately it's just as broken.

Yeah I figured it was a language bug Sad Sad

What should I do then??
Logged

raigan
Level 5
*****


View Profile
« Reply #9 on: August 06, 2010, 05:46:01 AM »

What should I do then??

What's wrong with double-buffering as suggested before? Keep two bitmaps and ping-pong between them (reading from one and writing to the other) instead of trying to read+write from the same one.
Logged
rejwan
Level 0
**


View Profile
« Reply #10 on: August 06, 2010, 06:31:15 AM »

What should I do then??

What's wrong with double-buffering as suggested before? Keep two bitmaps and ping-pong between them (reading from one and writing to the other) instead of trying to read+write from the same one.

Hmm well it seems very redundant performance wise - the drawing process is a very costly one (not only hexes are drawn, also cities/units/resources/etc) - so I'd rather avoid drawing so much.

I'll attempt to use the bitmapdata.Draw() function, maybe it's not as buggy as the copyPixels one Smiley
Logged

rejwan
Level 0
**


View Profile
« Reply #11 on: August 06, 2010, 06:41:02 AM »

Alrighty - even though is seems very inefficient, when calling .clone() on the same bitmap patches this language bug.

So if you want to use copyPixels from a bitmapdata, you can do so changing the X axis, but to change the Y axis it needs to use .clone():

Code:
bufferBD.copyPixels(bufferBD.clone(), new Rectangle(0, HEX_HEIGHT, bufferBD.width, bufferBD.height - HEX_HEIGHT), new Point());
Logged

st33d
Guest
« Reply #12 on: August 06, 2010, 07:06:10 AM »

You should submit a bug report:

https://bugs.adobe.com/flashplayer/

Things like this won't get fixed otherwise.

(I'd do it myself but I didn't really follow what the problem was - I'm a bit tired this week.)
Logged
rejwan
Level 0
**


View Profile
« Reply #13 on: August 06, 2010, 08:44:09 AM »

You should submit a bug report:

https://bugs.adobe.com/flashplayer/

Things like this won't get fixed otherwise.

(I'd do it myself but I didn't really follow what the problem was - I'm a bit tired this week.)

K I posted that bug. thanks.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #14 on: August 07, 2010, 03:19:26 AM »

Double buffering shouldn't be that much more expensive. By flipping which bitmap is visible each frame, you are still doing the same amount of copying that you were before.
Logged
rejwan
Level 0
**


View Profile
« Reply #15 on: August 07, 2010, 03:46:31 AM »

I'm actually single buffering + moving the X/Y of the bitmap by up to 1 hex to each direction, which causes the illusion of scrolling and only draws new hexes when absolutely necessary.
Logged

agj
Level 10
*****



View Profile WWW
« Reply #16 on: August 08, 2010, 10:25:24 PM »

Ah, I came across this bug once before as well. The docs do warn you that something could go wrong by copying a bitmap into itself, and says that what it supposedly does internally is make a copy of it anyway, so, if you make the copy yourself, there would probably be no great performance loss.

...Or so I thought, but the latest version of the docs show no mention of this. Hm. Are you using the latest Flex or Flash release, by the way?
Logged

rejwan
Level 0
**


View Profile
« Reply #17 on: August 09, 2010, 01:51:28 AM »

3.2 if I'm not mistaken - migrating to Flex 4 is too much of a hassle atm.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic