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

    Debug assertion failed: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    Hello,

    I have a problem which i don't seem to be able te solve. I have implemented a function to convolve two images. However, when i have implemented it into Visual C++ it always seem to lock at the same place. The convolution itself goes well, but when the handler for the button (which operates the convolution) returns, i get the error message which says:

    Debug Assertion Failed!

    File: dbgheap.c
    line: 1017

    Expression: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    When i build the project in Release mode and run it, it will halt with the message: User breakpoint called from code at point 0x77f9193c and the debugger will show me a disassembly code and context NTDLL!77f9193c. I'm new to the debugger, so i really have no clue what it's about, but I most certainly have not included a breakpoint. If I click on OK and then resume executing everything still works fine. I really have no clue what this is about. In my image object I do some dynamically reservation of memory using new and delete [], can it be that it has something to do with that?

    Thanking you in advance for any thoughts on this!

    Greetz, han

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Debug assertion failed: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    In my image object I do some dynamically reservation of memory using new and delete [], can it be that it has something to do with that?
    Yes. My first thought is that you're writing into unallocated memory (either on the heap or on the stack).

    - petter

  3. #3
    Join Date
    Jan 2006
    Posts
    28

    Re: Debug assertion failed: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    Thank you for your answer. I checked it out, but I found what i already expected. If I deallocate memory I always set my pointer to NULL, and i have made it impossible to write to a NULL-pointer. Therefore, I don't see, what it can be that is going wrong. Also the number of pixels always check out.

    So if you have any second thought...

    (by the way, it was late last night... so I couldn't find all of the words... )

  4. #4
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Debug assertion failed: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    Quote Originally Posted by Lintworm
    If I deallocate memory I always set my pointer to NULL, and i have made it impossible to write to a NULL-pointer.
    Well, maybe your pointer is valid, but you can still do buffer overflows. Like this:
    Code:
    // allocate 10 bytes
    char* ptr = new char[10];
    
    // write to the 11th. byte
    ptr[10] = 0;
    Here I'm writing outside of the allocated range, and my app will most likely crash.

    - petter

  5. #5
    Join Date
    Jan 2006
    Posts
    28

    Re: Debug assertion failed: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    I know....

    Hmmm The compiler does say that it detected a memory leak. When i follow where it points to this function:

    Code:
    void Pic::SetDimensions(short newdim[3])
    {
        // Setting new dimensions
        dim[0] = newdim[0]; thisheader.dim[0] = newdim[0];
        dim[1] = newdim[1]; thisheader.dim[1] = newdim[1]; 
        dim[2] = newdim[2]; thisheader.dim[2] = newdim[2];
        
        // updating the number of pixels
        npix = dim[0] * dim[1] * dim[2];
        
        // (Re)allocating memory
        if (this->image16F != NULL) delete [] this->image16F;
        this->image16F = new float[npix];
    }

    The values for dim[0-2] are all bigger than zero. When I access the memory, I will use the value npix to check wether or not an index is valid. Am i missing something? (most probably...)

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Debug assertion failed: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    Quote Originally Posted by Lintworm
    Am i missing something? (most probably...)
    No way to know unless we have the entire code and run it ourselves.

    We have no idea what values those variables are, where and when the function is called, or any context whatsoever in the code you posted. So basically you're on your own until you can give us a compilable example that shows the error.

    Regards,

    Paul McKenzie

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