Click here to Skip to main content
14,876,187 members
Please Sign up or sign in to vote.
4.78/5 (3 votes)
Hi there,
I'm new to C++ and i've got a basic project i've made up, just to play around with templates. It consists of the following classes:

- enumerable (used much like IEnumerable in .NEt Framework code)
- list<Type> [inherits from enumerable] (provides basic add & remove alongside initial sizes)

- keyValuePair<KeyType, ValueType> (is a simple struct with 2 properties - key and value...

- dictionary<KeyType, ValueType> [inherits from list] (is a list, which uses keyValuePair

No error appears to occur until the end of my program exection. At this point the program simply hangs while executing my final instruction:

delete [] pDict;

My program currently does something no more complex than adding a few initial items to a dictionary, retrieving a list object filled with keys and then cleaning up... So I pause the debugger, it warns me:

The process appears to be deadlocked (or is not running any user-mode code). All threads have been stopped.

and it then points me to:

dbgrpt.c (line 360 - 363):
/* Report the warning/error */<br />        nCode = __crtMessageBox(szOutMessage,<br />                             _T("Microsoft Visual C++ Debug Library"),<br />                             MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);


and points out that the line containing _T("Mi... is where the error occured. As far as i can understand, this portion of the "dbgprt.c" file displays an assertion failed error message. In case that helps any:

szOutMessage = "Debug Assertion Failed!<br />    Program: ...iversity for the West of Scotland\Samples\Debug\Templates.exe<br />    File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cppLine: 52<br />    Expression: _BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse)<br />    For information on how your program can cause an assertion<br />    failure, see the Visual C++ documentation on asserts.<br />    (Press Retry to debug the application)";


I then proceded to search MSDN documentation and found nothing specific to help me... Unfortunately searches of this forum didn't help me get any further so here is my question:

Where should I look? and what should I be looking for as possible sources of the error?

I've checked for un-initialised variables, memory leaks, and ensured (i think) all functions that return a value have a variable to be copied into so as to clean the stack... and so far all seems fine.

Thankyou for reading.
Posted

1 solution

First question: Was pDict allocated as an array, i.e.
pDict = new pDictType[size];
You are using the array delete syntax (delete []pDict). If pDict is a simple pointer, then using the array delete will Do Bad Things.

Other than that, the general things I can suggest are to step through the code and ensure that you're not walking over something in the stack. The symptom you are describing (all threads exited) sounds like a stack overwrite.

   
  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900