Solved

MFC Debug assertion failed in release version

Posted on 1997-03-13
1
594 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now