Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

brassfish89

error in dbgheap.c

This topic is 5567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

whenever i press enter in my title screen msvc points me to this in dbgheap.c and the debugger says szFileName is a < BadPtr >:
pvBlk = _heap_alloc_dbg(nSize, nBlockUse, szFileName, nLine);
  
here's the whole function:
/***
*void * _nh_malloc_dbg() - Get a block of memory from the debug heap
*
*Purpose:
*       Allocate of block of memory of at least size bytes from the debug
*       heap and return a pointer to it. Assumes heap already locked.
*
*       If no blocks available, call new handler.
*
*       Allocates any type of supported memory block.
*
*Entry:
*       size_t          nSize       - size of block requested
*       int             nhFlag      - TRUE if new handler function
*       int             nBlockUse   - block type
*       char *          szFileName  - file name
*       int             nLine       - line number
*
*Exit:
*       Success:  Pointer to (user portion of) memory block
*       Failure:  NULL
*
*Exceptions:
*
*******************************************************************************/

void * __cdecl _nh_malloc_dbg (
        size_t nSize,
        int nhFlag,
        int nBlockUse,
        const char * szFileName,
        int nLine
        )
{
        void * pvBlk;

        for (;;)
        {
#ifdef _MT
            /* lock the heap
             */
            _mlock(_HEAP_LOCK);
            __try {
#endif  /* _MT */

            /* do the allocation
             */
			pvBlk = _heap_alloc_dbg(nSize, nBlockUse, szFileName, nLine);

#ifdef _MT
            }
            __finally {
                /* unlock the heap
                 */
                _munlock(_HEAP_LOCK);
            }
#endif  /* _MT */

            if (pvBlk || nhFlag == 0)
                return pvBlk;

            /* call installed new handler */
            if (!_callnewh(nSize))
                return NULL;

            /* new handler was successful -- try to allocate again */
        }
}

here's my Title::update function:
   
void Title::update()
{
    if(timeGetTime()-waitTime<=200)
        return;
    input.UpdateKeys();
    // i still get the error even though this

    // is commented out

    /*if(input.KeyDown(DIK_RETURN))
    {
        if(currentSelection==0)
        {
            // start game
            state=Game::game;
            Game::game->init();
        }
        else if(currentSelection==1)
        {
            // show settings
            state=Settings::settings;
            Settings::settings->init();
        }
        else if(currentSelection==2)
        {
            // show highscore
            state=Highscore::highscore;
            Highscore::highscore->SetHighlight(-1);
            Highscore::highscore->init();
        }
        else if(currentSelection==3)
        {
            // exit
            PostQuitMessage(0);
        }
    }*/
    if(input.KeyDown(DIK_DOWN)&&timeGetTime()-lastDown>=200)
    {
        currentSelection++;
        if(currentSelection>3)
            currentSelection=0;
        lastDown=timeGetTime();
    }
    if(input.KeyDown(DIK_UP)&&timeGetTime()-lastUp>=200)
    {
        currentSelection--;
        if(currentSelection<0)
            currentSelection=3;
        lastUp=timeGetTime();
    }
}
does anyone know what could be causing this? thx brassfish EDIT: < BadPtr > didn't show up.
doh, nuts. Mmmm... donuts My website [edited by - brassfish89 on June 24, 2003 12:09:31 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The debug heap is a helper that visual c++ provides in your debug mode builds. It tracks allocations and deallocations and will tell you if you delete a pointer that is invalid, deleting a pointer twice etc.

The problem you experience is likely the result of your program deleting an invalid pointer.

The debug heap is your friend. Read more about it in MSDN: http://www.google.com/search?q=site:msdn%2Emicrosoft%2Ecom+debug+heap

Share this post


Link to post
Share on other sites
i dont think i delete any pointers in any of the class''s functions. it seems to be triggered by holding down enter for a second (i have to hold it down so long because im in debug mode). is there any way i can see where it is deleting an un-initialised pointer?



doh, nuts. Mmmm... donuts
My website

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"delete NULL;" is safe, but NULL is initialized, not just a random value.

delete does *not* check whether it''s safe to delete a random pointer, you should read more about how C/C++ memory management works if you did''nt know this.

When you break into the debugger, look at the call stack and you will see the exact location of your invalid delete.

It''s hard to in a few sentences teach how to understand all of this and teach you how to setup the debugger. There''s plenty of information on MSDN. John Robbins (http://www.wintellect.com/about/instructors/robbins/default.aspx) has written a few really good articles and a book on debugging.

Share this post


Link to post
Share on other sites
ok, i tried that. but it just points me to the place in my first post. i did find out it (heap_alloc_dbg) is being called from malloc. but it doesn''t show me where in my code its happening.



doh, nuts. Mmmm... donuts
My website

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
When you crash in the debugger. Look under the submenu "Windows" from the "debug" menu. There you can open the "call stack" window. Double-Click on the lines in the call stack to walk the stack and see from where the call originates.

Share this post


Link to post
Share on other sites
i did that already. but it only showed up to malloc. it didn't show anywhere in my code that im calling it. it also had some other stuff-above malloc. this is what the whole thing looked like:

kernel32.dll!77e6d756()
kernel32.dll!77e6d756()
compentry.exe!_nh_malloc_dbg(unsigned int nSize=33, int nhFlag=1243780, int nBlockUse=4581241, const char * szFileName=0xe06d7363, int nLine=1) Line 260 + 0x15 C
compentry.exe!malloc(unsigned int nSize=0) Line 139 + 0x15 C

when i click on the bottom one i go to the place in malloc its being called. when i click on one higher up (malloc) i go to the place in my first post.



doh, nuts. Mmmm... donuts
My website

[edited by - brassfish89 on June 22, 2003 10:48:15 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!