CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2009
    Posts
    4

    _CrtIsValidHeapPointer assert failure

    I've created a simple Windows Forms Application in MSVS 2005:
    - Use MFC in a Shared DLL
    - /clr
    I inserted the 2nd include for <afxtempl.h> as shown below:

    =================================================================
    // test1.cpp : main project file.

    #include "stdafx.h"
    #include <afxtempl.h>
    #include "Form1.h"
    using namespace test1;


    [STAThreadAttribute]
    int main(array<System::String ^> ^args)
    {
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
    }
    ==================================================================

    The debug build crashes with _CrtIsValidHeapPointer assertion. Releas build is ok. So far didn't have any success in finding out why this happens. Any help will be greatly appreciated. Thx.

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: _CrtIsValidHeapPointer assert failure

    Quote Originally Posted by eromascanu View Post
    The debug build crashes with _CrtIsValidHeapPointer assertion.
    An assert is NOT a crash. At least, not yet
    Quote Originally Posted by eromascanu View Post
    Releas build is ok.
    In Release build, asserts are not compiled into the binary, that is why you don't see it.
    Quote Originally Posted by eromascanu View Post
    So far didn't have any success in finding out why this happens.
    Are you saying that this is your complete code? Where does it assert?
    When assert fails, you can usually hit a Retry button and get right into your code to examine call stack, variables, etc.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Dec 2009
    Posts
    4

    Re: _CrtIsValidHeapPointer assert failure

    Thx Vladimir. The assert failure is in dbgheap.c - the last line in this sample.

    xtern "C" _CRTIMP size_t __cdecl _msize_dbg (
    void * pUserData,
    int nBlockUse
    )
    {
    size_t nSize;
    _CrtMemBlockHeader * pHead;

    /* validation section */
    _VALIDATE_RETURN(pUserData != NULL, EINVAL, -1);

    /* verify heap before getting size */
    if (check_frequency > 0)
    if (check_counter == (check_frequency - 1))
    {
    _ASSERTE(_CrtCheckMemory());
    check_counter = 0;
    }
    else
    check_counter++;

    _mlock(_HEAP_LOCK); /* block other threads */
    __try {

    /*
    * If this ASSERT fails, a bad pointer has been passed in. It may be
    * totally bogus, or it may have been allocated from another heap.
    * The pointer MUST come from the 'local' heap.
    */
    _ASSERTE(_CrtIsValidHeapPointer(pUserData));

  4. #4
    Join Date
    Dec 2009
    Posts
    4

    Re: _CrtIsValidHeapPointer assert failure

    Yes, it's the complete code. Very easy to duplicate the problem. I looked into the call stack, and it doesn't help because practically all the code - except that include <afxtempl.h> - is generated by .NET. The problem came from a bigger project, where I need the CList class which requires <afxtemp.h> header. I peeled off the code until I got this minuscule project that duplicates my problem.

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: _CrtIsValidHeapPointer assert failure

    Sorry, can't follow your steps to recreate this assert...
    Could you post a complete zipped project?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    Join Date
    Dec 2009
    Posts
    4

    Re: _CrtIsValidHeapPointer assert failure

    Sure. Here it comes...
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured