I brought this issue up months ago, back in 1.4.0 as a potencial problem when TRANSLUCENT VolatileImages eventually get implemented.
Now in 1.5 they finally have been I’m not seeing anything in the API that has been changed to ever make TRANSLUCENT VolatileImages work reliably.
The loop suggested in the API for ensuring a VolatileImage is draw correctly simply does not work when dealing with TRANSLUCENT images, the reason is because when performing a TRANSLUCENT blit, both the source and destination pixels contribute to the resultant pixel color.
The destination pixel will therefor be effectively corrupt if you render the source image twice.
Heres the sequence of operations that causes the problem.
-
Validate VolatileImage to make sure its ok to blit.
-
blit it to the backbuffer.
3) outside event causes the VolatileImage to lose its contents.
-
contentsLost is called, and returns true.
-
so your code has to restore the VolatileImage.
-
and then re-blit it to the backbuffer. etc etc.
This loop could potencially go on forever, but for simplicity lets say it happens only twice.
This still means a TRANSLUCENT image has been rendered onto the backBuffer twice, when it should have only been rendered once.
This will result in incorrect pixel values in the destination.
So, am I missing something - or are Volatile TRANSLUCENT images kinda fundamentally buggy?
[edit]
I guess the simplest solution is to change the definition what contentsLost() returns.
Instead of a boolean indicating whether the contents has been lost since the last call to validate(),
it should be changed to indicate if the contents has been lost since the last time the image was drawn?
[/edit]
p.s. I assume managed BufferedImages can behave in the exact same way, as their cached copy in vram can potencially lose its contents at any time also?