CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Dec 2006
    Posts
    60

    Re: Program crashes when closing

    Quote Originally Posted by Paul McKenzie
    Yes.
    Deleting NULL is safe in C++. The part that sounds suspicious is the "accidentally delete" part. You should never "accidentally delete". All the "deletes" must be done for a purpose, and at the correct times.

    Regards,

    Paul McKenzie
    I was just saying that as a response to JernauGurgeh. He suspected that something was beging deleted twice. I'm fairly confident that I do not, but mistakes happen. Also, most the allocated memory are local to functions, and I've checked each function for deallocation.

  2. #17
    Join Date
    Dec 2006
    Posts
    60

    Re: Program crashes when closing

    Quote Originally Posted by wildfrog
    Code:
    // main thread
    //...
    
    // Stop worker thread
    bStop = true;
    
    // Wait for thread to stop
    WaitForSingleObject(hThread, INFINITE); // wait forever until hThread has stopped
    
    // Clean up
    // ...
    How do i retreive a thread handle from a worker thread?

  3. #18
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Program crashes when closing

    Quote Originally Posted by acerunner316
    How do i retreive a thread handle from a worker thread?
    If you're using the WinAPI then the thread handle is returned by the CreateThread function. Or, using MFC you can get the handle through the CWinThread::m_hThread property.

    - petter

  4. #19
    Join Date
    Dec 2006
    Posts
    60

    Re: Program crashes when closing

    I've been working on this for several days now without any luck, and I'm getting a little desperate. I've attached my the code. If someone can take a look, I'd really appreciate it.
    Last edited by acerunner316; December 15th, 2006 at 06:54 PM.

  5. #20
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: Program crashes when closing

    Did your worker thread create this "class pointer" you're deleting?

    Code:
    //Monitoring Communications Worker thread control function
    UINT CNOx1000MonitorDlg::FuintMonitorComm (LPVOID PptrToClass)
    {
    ...
    	delete ptrWindowHandle;
    	delete LptrClass;   <-- this one
    
    	return 0;
    }
    Try commenting out this line.

    The worker thread routine is only using this pointer that was passed in - it's not yours to delete. The dialog will get destroyed on its own if you leave it alone.

    Hope this helps,

    - Nigel

  6. #21
    Join Date
    Dec 2006
    Posts
    60

    Re: Program crashes when closing

    Quote Originally Posted by NigelQ
    Did your worker thread create this "class pointer" you're deleting?

    Code:
    //Monitoring Communications Worker thread control function
    UINT CNOx1000MonitorDlg::FuintMonitorComm (LPVOID PptrToClass)
    {
    ...
    	delete ptrWindowHandle;
    	delete LptrClass;   <-- this one
    
    	return 0;
    }
    Try commenting out this line.

    The worker thread routine is only using this pointer that was passed in - it's not yours to delete. The dialog will get destroyed on its own if you leave it alone.

    Hope this helps,

    - Nigel
    Preliminary testing prooved that it worked. Thank you so much!

    That code has been there the entire time since the very first versions of the app even before I took over the project. I wonder why the problem has only just come up... Whatever the reason, thank you very much for taking the time to look at my code.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured