Solved

Assert Error when deleting a CDialog Object

Posted on 2004-03-22
11
491 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 116
paragon account problem 9 96
NotAlone Challenge 20 72
firstChar challenge 13 86
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

762 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

18 Experts available now in Live!

Get 1:1 Help Now