?
Solved

MFC Debug assertion failed in release version

Posted on 1997-03-13
1
Medium Priority
?
616 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
[X]
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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

770 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