Page 1 of 2

Animation restrictions?

Posted: Thu Dec 04, 2008 1:09 pm
by Sega-Zero
Are there any restrictions to animators? Wrote my own gif implementation and have noticed, that sometimes (espesially when there are a lot of animations are inside rv and while scrolling it) animation dissapears (just a rv background is drawing, like animator is skipped). That is definetly not a bug of my lib, have checked everything. RichView just don't paint it for some reason i can't understand...

So, is there any way to force animator painting?

Posted: Thu Dec 04, 2008 8:42 pm
by Sergey Tkachenko
Animations is supported only for the following gif implementations:
-TGifImage by Anders Melander,
- TGifImage included in Delphi 2007-2008
- TJvGifImage from JVCL.
Did you implement a special TRichView animator like it was implemented for these classes? Animators for these classes are in units: RVGifAnimate, RVGifAnimate2007, RVJvGifAnimate.

Posted: Thu Dec 04, 2008 9:04 pm
by Sega-Zero
yes. I did like in TRVGifImageAnimator. At what cases animator cannot be drawn?

Posted: Fri Dec 05, 2008 11:49 am
by Sergey Tkachenko
There is a limit on animators count (const RVMaxAnimations: Integer = 100000), but I doubt you exceed it.

Posted: Fri Dec 05, 2008 12:03 pm
by Sega-Zero
no, i've tested it on 50k gifs. But it is just to reproduce the bug. it appears even on small count of animations, but it is hard to catch it then. This is happening after some hours of intensive work with adding/removing gifs.

The strangiest thing is that gif appears again when animation cycle starts from the beginning. It's kinda mystery for me

Posted: Fri Dec 05, 2008 1:27 pm
by Sergey Tkachenko
Try the same test with another gif implementation

Posted: Fri Dec 05, 2008 5:33 pm
by Sega-Zero
exactly the same test is impossible. too many GDI leaks. thats the reason i wrote my lib for. TGifImage brakes application in a few scrolls of whole area with EOuOfMemory. TjvGifImage even less.

could you please tell me how TAnimator work and in what cases it cannot be drawn?

P.S. working on Delphi 7

Posted: Fri Dec 05, 2008 6:08 pm
by Sergey Tkachenko
In my test, there were no GDI leaks with TGifImage.
And GDI resources are minimally used when animations are inserted in TRichView, because TRichView animates them itself, not using their built-in animation features.
What version of TRichView do you use? May be you use older version, which used much more resources for animation, and had much smaller default value of RVMaxAnimations?

Posted: Fri Dec 05, 2008 6:18 pm
by Sega-Zero
using the last version. gdi leaks are present - scroll the whole area (by dragging vertical scrollbar with mouse) fast up and down - in a few iterations it will fall (gdi leaks gets from somewhere inside TGifImage, while extracting frame bitmap). That is not accepteable for me...

Posted: Fri Dec 05, 2008 6:22 pm
by Sega-Zero
forgot to say, i don't think this is a limitation problem - animators are not skipped at the end. They skipped randomly within drawing area

Posted: Fri Dec 05, 2008 7:04 pm
by Sergey Tkachenko
I cannot reproduce the problem with TGifImage.
I created a test project:

Code: Select all

var i: Integer;
    gif1, gif2: TGifImage;
begin
  gif1 := TGifImage.Create;
  gif1.LoadFromFile('kengu.gif');
  for i := 1 to 20000 do begin
    gif2 := TGifImage.Create;
    gif2.Assign(gif1);
    RichView1.AddPictureEx('', gif2, 0, rvvaBaseLine);
  end;
  gif1.Free;
  RichView1.Format;
end;
If animation is turned on (RVGifAnimate is included in the project, and RichView1.AnimationMode = rvaniOnFormat), I can scroll back and forth without problems. This is because animation is handled by TRichView, only memory for the current frame and only for visible animations are allocated.
If animation is turned off, the program really fails. But it's not because leaks, but because too many objects used. In this mode, images are shown using Canvas.Draw method. On each repainting, TGifImage displays a new frame (and creates a new bitmap for it). When I scroll back and forth, more and more frames are displayed, and more and more bitmaps are created, until the application fails. But again, it happens only if animation is turned off.

The last version of TRichView is 11.0.1 (11.0 is also ok).

Sorry, I do not know why your animators are not shown. Probably something is wrong with them, because I cannot reproduce this problem with TGifImage.

Posted: Fri Dec 05, 2008 7:23 pm
by Sega-Zero
try this code. this will reproduce gdi leak bug easyly (especially when set the size of a window larger so the drawing area could be wider):

Code: Select all

var i: Integer; 
    gif1, gif2: TGifImage; 
begin 
  gif1 := TGifImage.Create; 
  gif1.LoadFromFile('kengu.gif'); 
  for i := 1 to 20000 do begin 
    gif2 := TGifImage.Create; 
    gif2.Assign(gif1); 
    RichView1.AddPictureEx('', gif2, -1, rvvaBaseLine); 
  end; 
  gif1.Free; 
  RichView1.Format; 
end;
try to scroll it now.

But my problem is not a gdi leak (that is not a problem for me now). The problem is animation dissapearing...

Posted: Fri Dec 05, 2008 8:12 pm
by Sergey Tkachenko
Well, you are right. While bitmaps were ok (used minimally), there is one more type of resource that is accumulated for each image: palettes.
I opened RVGifAnimate.pas, and added after
TGifSubImageHack(gif.Images[FrameIndex]).FreeMask:

Code: Select all

      TGifSubImageHack(gif.Images[FrameIndex]).Palette := 0;
      gif.Palette := 0;
I am not sure if this change is harmless, but after it the problem is gone.

Sorry, I do not know why your images disappearing.
I cannot reproduce this problem with TGifImage.

Posted: Fri Dec 05, 2008 8:25 pm
by Sega-Zero
sorry to dissapoint you, but your patch isn't working. show a gif with at least 15 frames, and scroll content by mouse-scroll. And take a look at task manager and the process GDI objects parameter. TGifImage by Anders Melanders is really buggy :)

Maybe the source of animator will be more helpful? Will upload a video of animation dissapearing in a few minutes to demonstrate how this is happening

Posted: Fri Dec 05, 2008 8:59 pm
by Sega-Zero
here is the source of animator.
here is the video that describes the effect.

As you can see at the video, I've set the background of gif manually to the green color. (Instead of

Code: Select all

RVData.GetItemBackground(RVData.DrawItems[item.DrawItemNo].ItemNo, R, True,
    FBackColor, bmpsrc, UseSrcBitmap);

  gif.BackGroundColor := FBackColor;
  if UseSrcBitmap then
    gif.BackGroundBitmap := bmpsrc;
i've commented that block and set

Code: Select all

gif.BackGroundColor := clGreen;
)

But sometimes, randomly, instead of drawing gif RV shows empty rect. That is definetly not a bug of the lib. But it could be wrong animator code. Maybe i lost something important. Something that tells RV not to draw it...