Solved

Assert Error when deleting a CDialog Object

Posted on 2004-03-22
11
495 Views
Last Modified: 2013-11-20
All of the sudden my code started giving me Assert Errors everytime I delete a CDialog object created with new.  It didn't used to do that and I can't figure out what has changed.  For example the following code gives me an Assert error on the delete line:

      CEditStringDlg *pEditStringDlg=NULL;
      pEditStringDlg = new CEditStringDlg;
      pEditStringDlg->DoModal("Testing...", "Testing...", &m_TempDirectory);
      delete pEditStringDlg;

Of course if I do not use delete the CDialog is dumped at program close.  Any ideas why this is giving me this error?

Thanks,
David Johns
0
Comment
Question by:david_johns
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 10647395
Can u post the Assert Text...
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10647729
Is there a reason why you dont do the following?

CEditStringDlg dlg(this);
dlg.DoModal(...);
0
 

Author Comment

by:david_johns
ID: 10650799
Roshmon,

The assert text is as follows:

File: dbgheap.c
Line: 1084

Expression: pHead->nBlockUse==nBlockUse


AndyAinscow,
Sometimes I do.  The case I posted was just an example I tried when I started having problems.  The problem that brought my attention to it is that I am switching between 3 child dialogs in my main dialog and I create them in this manner and then delete them when another one is in use.  I suppose I could just have all three of them running and show or unshow them then delete them at the end, but I would still have this problem eventually.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10651141
But DoModal is to show a dialog once and have the user respond to it.  You seem to imply you call DoModal multiple times on it.
0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 10651149
This assertion failure means that the heap has got corrupted. You may have overwritten memory that does not belong to you. If it consistenly happens there, you can check the address of pHead->nBlockUse and watch the memory while stepping thru the code to see where in you code overwrites it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:david_johns
ID: 10651437
AndyAinscow,

No, acutally I am using create on the majority of my dialogs and running them modeless.  I just noticed the problem with my child windows and then tried this very simple testcase to see if the same problem occured on them and it seems to happen with every dialog I allocate using new.

Chensu,

I figured this was probably an overwrite, but it seemed wierd to me that it happens every I put it.  Actually I even tried it in a seperate project and got the same result.  I should try it with a completely clean project, but it really suprized me when it occured in both this project and a very very simple on that I also tried it in.
0
 

Author Comment

by:david_johns
ID: 10651737
So - I tried it in a new project and played around a bit.  When I use new to declare it as an array it works.

Ex:
    pDlg = new CTestDlg[1];
    .....
    delete[] pDlg;

But even in a completely clean project it doesn't work with my original approach - so it seems not to be heap corruption.  Anyone know why this happens?  Is this the only way to get this to work?  Perhaps this is how I got around it before, but I don't remember having to do this.
0
 
LVL 23

Expert Comment

by:chensu
ID: 10651927
In the completely new project, did you change any other code? Did you add any code to the CTestDlg class?
0
 

Author Comment

by:david_johns
ID: 10652944
Nope - The  test project was straight out of the app wizard.  I just put a bit in the initinstance that made the dialog using 'new' instead of creating it in local memory.  I left the dialog just as it comes out of appwizard and added no other functions.
0
 
LVL 23

Expert Comment

by:chensu
ID: 10653692
Please show the InitInstance() code.
0
 

Author Comment

by:david_johns
ID: 10655501
So this is embarassing but I tried it again and couldn't recreate the problem.  I looked into it more and figured out that I had actually launched a dialog I created in a static library I made rather than the CTestDlg.  I then looked into my library a bit and cleaned out some classes I was not using.  It worked then.  Either I had a bad build of the library or there was some problem with those classes.  Thanks everyone for the help.

David Johns
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 66
Strange date stored 22 106
Perl Awk Need Help 3 109
unix example issues 18 73
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now