Archived

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

Debug Assertion failed message

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

Recommended Posts

hi All, I am stumped as to why i get "Debug Assertion failed" message when i am in Debug mode, yet in Release mode i get no errors! THe exact error message is this:
  --------------------------- Microsoft Visual C++ Debug Library --------------------------- Debug Assertion Failed! Program: C:\source\OGL\Debug\OGL.exe File: dbgheap.c Line: 1011 Expression: _CrtIsValidHeapPointer(pUserData) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) --------------------------- Abort Retry Ignore --------------------------- 
OGL.exe is my application which caused the error. After debugging, I noticed the error occurs when i free the pointer of type float. This is the exact point where the error occurs (the free() function call):
  if (Scene->objlist[n].NormalFaceArray) free (Scene->objlist[n].NormalFaceArray); 
The problem is I have defined NormalFaceArray as a pointer of type float and stepping through the program the address is null (0x00000). (which is correct) So why is it still going through the free() call? This error doesnt occur in release mode, yet i get it in debug mode! Any pointers as to what mistake I have made? thanks. Xtreme. Edited by - Xtreme on February 4, 2002 5:14:14 AM

Share on other sites
Are you sure that the error occurs with a NULL pointer, since NULL is valid for free anyway. Put a breakpoint on the line with the free and have a closer look.
The cause that you don''t get the message with a release build is that the release version of the runtime doesn''t check the heap.

Share on other sites
yes,
i have tried it by assigning NULL to it, and it tries to
free it!

Share on other sites
quote:
Original post by Xtreme
yes,
i have tried it by assigning NULL to it, and it tries to
free it!

Can''t be,
but to be sure, just write

  if( Scene->objlist[n].NormalFaceArray != NULL ){ free (Scene->objlist[n].NormalFaceArray);}

Make SURE you don''t have a stray semicolon at the end of that if-line.
If the pointer is null, you will not enter the if-block. If it enters the if-block, the pointer was NOT null.

People might not remember what you said, or what you did, but they will always remember how you made them feel.

Share on other sites
VolkerG, you can not pass NULL to "free ()". I think it may be safe to pass NULL to "delete" though.

- Pete

Share on other sites
ok, this is wat i got now:

  ---------------------------Microsoft Visual C++ Debug Library---------------------------Debug Assertion Failed!Program: C:\source\OGL\Debug\OGL.exeFile: dbgheap.cLine: 1017Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)For information on how your program can cause an assertionfailure, see the Visual C++ documentation on asserts.(Press Retry to debug the application)---------------------------Abort Retry Ignore ---------------------------

The expression is a bit different but still i get this!

Share on other sites
Just to show you that i has assigned NULL to it:

  OGLObject * OGL_3dsloader::GetObject(){ void * mem; uint size = sizeof(OGLObject)*(Scene->objects+1); if((mem=realloc(Scene->objlist, size)) == 0) { sprintf(emsg, "Error reallocating memory for object list " "(%u bytes).", size); throw emsg; } Scene->objlist=(OGLObject *) mem; OGLObject * obj=&Scene->objlist[Scene->objects++]; memset(obj, 0, sizeof(OGLObject)); Scene->objlist->ColourArray = NULL; Scene->objlist->NormalArray = NULL; Scene->objlist->NormalFaceArray = NULL; Scene->objlist->TextureArray = NULL; Scene->objlist->VertexArray = NULL; return obj;}

This is the object structure defintion:

  typedef struct OGLObject{ ushort faces; /* number of faces in facelist */ ushort vertices; /* number of vertices in vtxlist */ uchar color; /* mesh color index [0...63] */ char name[16]; /* object name, zero terminated */ OGLFace * faclist; OGLVertex *vtxlist; float *VertexArray; /* To be used with glVertexPointer */ float *TextureArray; /* To be used with glTexCoordPointer */ float *ColourArray; /* To be used with glColorPointer */ //float *NormalVertexArray;/* To be used with glNormalPointer */ float *NormalFaceArray; /* To be used with glNormalPointer */ float *NormalArray;} OGLObject;

and this is my memory deallocation part:

  void OGL_3dsloader::OGLFreeScene(){ if(Scene) { if(Scene->objlist) { for(int n=0; nobjects; n++) { if(Scene->objlist[n].faclist) free(Scene->objlist[n].faclist); if(Scene->objlist[n].vtxlist) free(Scene->objlist[n].vtxlist); } if (Scene->objlist[n].VertexArray) free (Scene->objlist[n].VertexArray); //if (Scene->objlist[n].NormalVertexArray) // free (Scene->objlist[n].NormalVertexArray); if (Scene->objlist[n].NormalFaceArray) free (Scene->objlist[n].NormalFaceArray); if (Scene->objlist[n].NormalArray) free (Scene->objlist[n].NormalArray); if (Scene->objlist[n].TextureArray) free (Scene->objlist[n].TextureArray); if (Scene->objlist[n].ColourArray) free (Scene->objlist[n].ColourArray); free(Scene->objlist); } if (Scene->matlist) free(Scene->matlist); free(Scene); Scene = NULL; }}

Edited by - Xtreme on February 4, 2002 6:52:38 AM

Share on other sites
to siaspete from the MSDN Library:
Remarks
...
If memblock is NULL, the pointer is ignored and free immediately returns.
...
And to Xtreme: why is in the OGL_3dsloader::OGLFreeScene method the block beginning with VertexArray after the closing brace of the for loop? Here you are adressing with n pointing behind the end of your array, aren't you?

Edited by - VolkerG on February 4, 2002 7:38:46 AM

Share on other sites
Volker, i dont quite understand your question but basically
the "n" is the object structure count and that structure
is part of a bigger structure, ie,
OGLObject * objlist; /* array of objects */

so i have to go through all of the objects and delete them
anyway, problem doesnt occur there, it fails it the
if (Scene->objlist[n].NormalFaceArray)
free (Scene->objlist[n].NormalFaceArray);

point!

Share on other sites
quote:
Original post by Xtreme
so i have to go through all of the objects and delete them
anyway, problem doesnt occur there, it fails it the
if (Scene->objlist[n].NormalFaceArray)
free (Scene->objlist[n].NormalFaceArray);

point!

No. Volker is right. If that''s your exact code, you will be attempting to free a block that is in fact past memory that you have allocated. In the code causing the problem, n is equal to Scene->objects, meaning you are accessing one element beyond the end of the array. You have to put the frees WITHIN the for loop.

People might not remember what you said, or what you did, but they will always remember how you made them feel.

• 10
• 17
• 9
• 14
• 41