Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Assert Error when deleting a CDialog Object

Posted on 2004-03-22
11
502 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 169
dog bark java program 15 105
either24  challenge 19 101
scoreUp challenge 14 63
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

790 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