Flicker-free animation routine crashes 
Author Message
 Flicker-free animation routine crashes

Env: VC4.0, Win95


I have derived a CMyImageList class from CImageList. I want to move an
image of the list in a straight line from between two given points. To
avoid flicker, I use validation to redraw only the needed parts. This
works quite well, but after a two or three animations, I get a message
box saying EXACTLY "A needed resource was" and an OK button. Clicking
the button makes the message box reappear. If the De{*filter*} is on, it
says "fatal error: uncaught exception" and a hex address.

I then replaced my code with a more flickery version that BitBlt's from
a memory DC, and the error disappeared. However, when the program was
run for a long while (the function called thousands of times), the same
error occured a couple of times. I observed when the message box
appeared, the animation frames were drawn, but the background was not
drawn, leaving the old frames on screen. I thought the problem might be
in the animation function or in my OnEraseBkgnd, so I include the code
for both, replacing irrelevant params with constants.

If anybody can figure out what goes wrong, I'll be most grateful. Thank

void CMyImageList::Fly(
        CDC *pDC,       // DC to draw into
        int nImage,     // index of image in ImageList
        CPoint PtSrc,   // starting point
        CPoint PtDest,  // ending point
        CWnd *pWnd = pDC->GetWindow();
        // Set step sizes. No problem here.
        CSize Stepsize((PtDest.x - PtSrc.x) / 10,(PtDest.y - PtSrc.y) /
        for (int i = 1; i <= 10; i++, PtSrc += Stepsize)
                // Draw the image
                // Mark drawn area for update
                if (i<subdiv) // This is to exclude the last draw which
will stay
                        // To remove flicker. Remove overlapping part
from update region.

                // Delay here.
                // This will now clear the part of the old image not
overlapped by the new image.
                //Delay ends here.
        // The last frame. Stays, as mentioned.


BOOL CMyView::OnEraseBkgnd(CDC* pDC)
        // Set brush to desired background color
        CBrush backBrush(BACK_COLOR);
        CRect rect;
        pDC->GetClipBox(&rect); // Erase the area needed
        pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),

        // This merely draws some rectangles.
        return TRUE;


       . .
+--oOO (_) OOo-------------------------------+-----------------------+
|       -                                    |  Bogazici University  |

|       URL: http://www.*-*-*.com/ ;     |

Fri, 10 Mar 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Flicker-free animation routine crashes

2. SOLUTION: How To Do Flicker-Free Animation with MSChart in C++/MFC

3. HELP : Flicker Free Animation In TC.

4. Animation and flickering?

5. Bitmap animation causing flicker

6. Flickering animation

7. Flicker with Common controls using OnTimer and animation????

8. How to stop Cursor Flickering ontop of animation??

9. How to stop Cursor Flickering ontop of animation??

10. C routines for animation

11. animation control crashes

12. Fast List Control (Flicker Free and High Performance)


Powered by phpBB® Forum Software