Runtime error
I've created a game that has lots and lots of pointers that I call new and delete on, from what i can tell, safely so that there are no memory leaks. On one specific instance where I open a file, read in mass amounts of data, store them in pointeres; then I close the file, delete them all. That part is fine, but when I want to load the file again, I get a window that says this:
"Windows has triggered a breakpoint in Counter-Degree.exe.
This may be due to a corruption of the heap, and indicates a bug in Counter-Degree.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information."
Is there any way I can isolate the problem? When I look in my debugger the call stack is on a call to a new pointer:
> msvcr80d.dll!memcpy_s(void * dst=0x01320000, unsigned int sizeInBytes=1073741920, const void * src=0x00000164, unsigned int count=356) Line 67 + 0x11 bytes C
msvcr80d.dll!_heap_alloc_base(unsigned int size=356) Line 105 + 0x28 bytes C
msvcr80d.dll!_heap_alloc_dbg(unsigned int nSize=320, int nBlockUse=1, const char * szFileName=0x00000000, int nLine=0) Line 409 + 0x9 bytes C++
msvcr80d.dll!_nh_malloc_dbg(unsigned int nSize=320, int nhFlag=0, int nBlockUse=1, const char * szFileName=0x00000000, int nLine=0) Line 266 + 0x15 bytes C++
msvcr80d.dll!malloc(unsigned int nSize=320) Line 152 + 0x15 bytes C++
msvcr80d.dll!operator new(unsigned int size=320) Line 59 + 0x9 bytes C++
Counter-Degree.exe!Wrath::WUtility::ptWVectorList<Wrath::WEntity::cW3dsModel::sWMeshMaterial>::Add() Line 899 + 0xa bytes C++
What does that mean?
Quote:
Counter-Degree.exe!Wrath::WUtility::ptWVectorList<Wrath::WEntity::cW3dsModel::sWMeshMaterial>::Add() Line 899 + 0xa bytes C++
The problem seems to be caused by adding an object (Wrath::WEntity::cW3dsModel::sWMeshMaterial ) into a list (std::vector, I assume? )
It means that somewhere you have memory corruption (Or some other error), usually caused by the use of pointers. This can also indicate that you have a memory leak somewhere.
Quote:
On one specific instance where I open a file, read in mass amounts of data, store them in pointeres; then I close the file, delete them all. That part is fine, but when I want to load the file again, I get a window that says this:
While it may, or may not, be the problem, this is the first place I would look.
Debug this function, and watch the heap while debugging, and insure it is what you expect it to be.
If you cannot find the problem, is it possible to post your code?
It may also be that this function relies on other objects and functions that were not properly initialized, created, or properly coded (ie, creates a memory leak)
I apologize, I should have been more clearer.
What I mean was watching the values in the vector, and associated variables, and insure that the values they contain are what you expect them to be.
What I mean was watching the values in the vector, and associated variables, and insure that the values they contain are what you expect them to be.
See, what's weird about that is I know nothing is wrong because I use that data to render a huge object (a .3ds model to be exact, from 3ds max) and when I Unload() it, i delete and close all the vectors<> down. Its just when re-Load() it in, that's when it get that. which is why i'm so confused
Assuming that those routines are not that big, is it possible to post them?
It might be helpful as someone else's eyes might be able to spot the problem.
Wait... Is that a seperate function then your Load() and unload() routines?
It might be helpful as someone else's eyes might be able to spot the problem.
Quote:
Its just when re-Load() it in, that's when it get that.
Wait... Is that a seperate function then your Load() and unload() routines?
no, I just have Load() and Unload()
I would post both functions, but the Load is a very long function with little recursive functions in it that reads a .3ds file and the Unload() is pretty long function as well and yes i use the vector<> but i wrap it with my own template and it would really be too much... is there any other way to debug it myself?
I would post both functions, but the Load is a very long function with little recursive functions in it that reads a .3ds file and the Unload() is pretty long function as well and yes i use the vector<> but i wrap it with my own template and it would really be too much... is there any other way to debug it myself?
Hmm...
Perhaps something is not getting cleaned up properly?
Assuming that your loading routine works properly (as it seems to be); if it uses any object that was not properly cleaned up by your Unload() routine, the results are undefined.
If you call both routines once, even if your Unload() function does not clean up properly, it will still work as those routines are never called again. (You will have a memory leak, however.) This will explain why it works the first time.
However, if your load() routine uses objects not properly cleaned up (After Unload() was already called), it can cause memory curruption, as the objects were allocated on the heap. This will explain why it does not work after the first time, and the error you get.
I am thinking the problem is not your Load() routine, but your Unload() routine.
Perhaps something is not getting cleaned up properly?
Assuming that your loading routine works properly (as it seems to be); if it uses any object that was not properly cleaned up by your Unload() routine, the results are undefined.
If you call both routines once, even if your Unload() function does not clean up properly, it will still work as those routines are never called again. (You will have a memory leak, however.) This will explain why it works the first time.
However, if your load() routine uses objects not properly cleaned up (After Unload() was already called), it can cause memory curruption, as the objects were allocated on the heap. This will explain why it does not work after the first time, and the error you get.
I am thinking the problem is not your Load() routine, but your Unload() routine.
hmm... well here's my unload routine...
Shutdown() goes through every item in the vector<> and calls delete on it then removes it from the list.
void cW3dsModel::Unload() { for(WuLONG i = 0; i < m_Model.Objects.GetNetItems(); ++i) { for (WuLONG j=0 ; j <m_Model.Objects.GetItem(i)->MatFace.GetNetItems() ; ++j) { m_Model.Objects.GetItem(i)->MatFace.GetItem(j)->Faces.Shutdown(); m_Model.Objects.GetItem(i)->MatFace.GetItem(j)->Mat = NULL; } m_Model.Objects.GetItem(i)->MatFace.Shutdown(); for (WuLONG j=0 ; j <m_Model.Objects.GetItem(i)->Verts.GetNetItems() ; ++j) m_Model.Objects.GetItem(i)->Verts.GetItem(j)->AdjVerts.Shutdown(); m_Model.Objects.GetItem(i)->Verts.Shutdown(); m_Model.Objects.GetItem(i)->Faces.Shutdown(); m_Model.Objects.GetItem(i)->Normals.Shutdown(); m_Model.Objects.GetItem(i)->TexVerts.Shutdown(); } m_Model.Objects.Shutdown(); for (WuLONG i=0 ; i<m_Model.Materials.GetNetItems(); ++i) m_Model.Materials.GetItem(i)->Material.Shutdown(); m_Model.Materials.Shutdown(); m_bIsLoaded = false; }
Shutdown() goes through every item in the vector<> and calls delete on it then removes it from the list.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement