Thread: Windows MFC leaks CWinThread??

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001

    Windows MFC leaks CWinThread??

    I'm implementing an animation controller in my editor and have run across several issues.

    When the animation plays, the tiles that it displays will flicker in either the tile selection window or the view window if your mouse is in either one of them. I know this is due to the fact that my render for the windows is asking for the Tile DC at the same time the thread is asking for it. Perhaps a CSemaphore with a CSingleLock is in order?

    I'm using AfxBeginThread() to create the thread. According to MFC docs, this thread object will be destroyed when the app exits. Why then is MSVC complaining about a leaked CWinThread object? Even if I get a pointer to this thread there is no way to stop the thread via CWinThread and I cannot use delete because it was not created with new. Suggestions?

    Sharing DC's and getting this all to work across threads has been a royal pain.

    The thread simlply updates the animation time counters and then draws the animations in the correct windows using that window's dc. I couldn't use OnIdle() because it didn't get called enough to make the animation of any use. The animation works perfect, just have some issues to sort out with synchronization and leaking the main thread.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    WARNING: I'm an MFC novice.

    The CWinThread object is destroyed when the thread exits. You must make sure that every thread you create is finished before the main thread finishes.

    If the thread contains a window, you can do this by sending a message telling it to close. Otherwise, you will need to use some other form of synchronization.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Well I return when CWinApp goes out of scope. Perhaps it never returns. I dunno how to tell if the app is currently 'running' or not. The update portion of the thread is just a do while but I don't know when to exit because CWinApp doesn't have any members that tell me when the app is valid.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Books on C and C++
    By kermi3 in forum A Brief History of
    Replies: 16
    Last Post: 10-28-2002, 04:18 PM
  2. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  3. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  4. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM
  5. Docking Windows without MFC / C++ ???
    By novacain in forum Windows Programming
    Replies: 0
    Last Post: 09-17-2001, 02:44 AM