[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MFC Debug assertion failed in release version

Posted on 1997-03-13
1
Medium Priority
?
624 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

834 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