Solved

MFC Debug assertion failed in release version

Posted on 1997-03-13
1
609 Views
Last Modified: 2010-05-18
I'm currently building an application that makes extensive use of the ODBC class CRecordSet of the Visual C++ MFC classes. While writing my application, I've constantly worked in the Debug mode and my program works fine. However, when I rebuilt my program in the Release mode, I got the following debug assertion:
   Debug Assertion Failed
   Program C:\.....\myprogram.exe
   file: dbgheap.c
   Line: 1017
   Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

I've traced the problem (using printf throughout my code) to the CRecordSet::Open method used to open my database.

I would like to know how my program can cause a debug assertion at all after I've compiled it in release mode. Second of all, I'd like to know how to solve this problem. Could this be a wrong build-setting, or is my own code acting up somewhere? And if so, why does my code run perfectly during a debug session?

Thanks in advance for any suggestions / solutions.

Remko

PS: I made sure to do 'Rebuild All' when rebuilding for the release version.
0
Comment
Question by:fprwy
1 Comment
 
LVL 1

Accepted Solution

by:
rhgaracci earned 100 total points
ID: 1162299
It sounds like your project settings are specifying a debug MFC library to be linked in.  MFC uses the debug heap when it allocates memory for CObject derived objects.  It sounds like the heap is being corrupted by a write to an invalid memory address.  Rebuilding the application moves everything around in memory, and so the location of the corruption can move as well, which could explain why the problem doesn't manifest itself in the debug version.

Check your code for anywhere you write to memory using a pointer.   You may have an invalid pointer somewhere.  This can easily happen when processing arrays if you overrun the boundaries.



0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

792 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