Advertisement

Heap Error

Started by October 22, 2014 04:54 AM
10 comments, last by ankhd 10 years, 3 months ago

Hi all.

Whats does this here mean.


HEAP[RTSTowers.exe]: HEAP: Free Heap block 7155000 modified at 716af78 after it was freed
Windows has triggered a breakpoint in RTSTowers.exe.

This may be due to a corruption of the heap, which indicates a bug in RTSTowers.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while RTSTowers.exe has focus.

The output window may have more diagnostic information.
The program '[2432] RTSTowers.exe: Native' has exited with code 0 (0x0).

Does it mean Ive hit the limit of the stack Or is it I'm deleting and using it again.

How would I find Delete and using again this its saying. Because I dont delete any thing at init time only with classes on the stack that call there destructores and they all use std::vectors

But first I need to know what the error realy means Thanks.

The main causes will be a use-after-free, or a buffer-overrun error:


Foo* foo = new Foo;
delete foo;
foo->member = 42; // write-after-free
 
vector<Foo> myVector;
myVector.resize(10);
myVector[9000].member = 42; // out-of-bounds write

Application Verifier is a good windows tool that can help track these down, but it's complicated...

http://msdn.microsoft.com/en-us/library/windows/desktop/dd371695(v=vs.85).aspx

http://stackoverflow.com/questions/1010106/how-to-debug-heap-corruption-errors

http://blogs.msdn.com/b/lagdas/archive/2008/06/24/debugging-heap-corruption-with-application-verifier-and-debugdiag.aspx

Advertisement

There could be many reasons for such an error, try to look out for common pitfalls, something like this:


class SomeClass... 
{

   SomeOtherClass* newInstance() {
         SomeOtherClass myNewInstance;
         myNewInstance.someAttr = 1;
         return &myNewInstance; // <-- Bad idea !!
   }
}


// somewhere in your code
SomeOtherClass* myNewObject = SomeClassObj.newInstance();
myNewObject->someOtherAttr = "hello world"; //<-- Bad idea !!

While those are great examples of why it happens, usually the code is much more tricky to diagnose than those three line examples.

The patterns are the same but the bugs can be in very different parts of code. The allocation can be handled in one library, then the pointers go through your program, and you pass the pointers to a second library which maintains an out-of date pointer.

Also, they don't necessarily happen immediately. The condition can happen ages later. It is possible that some portion of the code was holding a pointer that was freed minutes later, or even hours or possibly days later in a long running program.

"Its Complicated" is the truth. Sometimes they are very easy to find. But sometimes they are nightmares. Coming in after memory corruption errors and race conditions, I'd rank it as probably the third biggest source of the nasty evil nemesis bugs that can haunt a code base for months or even years before isolating it and finding a fix.

I installed App Verifier. I then run the game it loads all the .x files in the main apps thread but when it gets to the load thread, all .X files fail here

pDXFile->CreateEnumObject(); no debug errors nothing just fails.

With out the app verifier running it all loads

The heap error only happens once every 10 to 15 runs or more.

Ashaman73 I have a static one like this

TextureMgr& GetTextureMgr()

{

static TextureMgr tm;

return tm;

}

Oh Just a thought while posting this if this is called on another thread is it the same object as in the main thread.?????????

It does have a error code here


HRESULT: 0x88760361 (2289435489)
Name: DXFILEERR_BADFILE
Description: n/a
Severity code: Failed
Facility Code: FACILITY_D3D (2166)
Error Code: 0x0361 (865)

But Its not a bad file.


Oh Just a thought while posting this if this is called on another thread is it the same object as in the main thread.?????????

As this is For Beginners, I'm going to recommend you rip out everything thread-related in your program right now.

Threading adds concurrency bugs and race conditions. If you thought this class of bugs was bad, concurrency bugs are far worse, since they are the same type of bugs compounded across a dimension of additional processes.

Remember when I wrote "Coming in after memory corruption errors and race conditions, I'd rank it as probably the third biggest source of the nasty evil nemesis bugs that can haunt a code base for months or even years before isolating it and finding a fix" above?

What you are saying is "I'm having trouble with the third-worst source of nasty bugs. Now I want to throw in the second-most evil source of nightmare fuel, and both of those sources can trigger the absolute worst of the three: memory corruption bugs. STOP. DO NOT PASS GO.

"Threading" and "For Beginners" are a terrible mix unless you enjoy spending your days hunting seemingly random crashes rather than learning useful material.

I strongly recommend you remove everything related to threading in your personal project, and stick with the much simpler realm of linear programming.

Advertisement

Ok I've made it single threaded, But every time the app verifier is running it makes CreateEnumObjects() return fail.

I did get this log from app verifier But I do not understand what its saying is the more info on it.



<?xml version="1.0" encoding="UTF-8"?>
-<avrf:logfile xmlns:avrf="Application Verifier"> -
<avrf:logSession Version="2" PID="4012" TimeStarted="2014-10-22 : 20:06:55"> -
<avrf:logEntry Severity="Error" StopCode="0x13" LayerName="Heaps" Time="2014-10-22 : 20:38:56"> 
<avrf:message>First chance access violation for current stack trace.</avrf:message> <
avrf:parameter1>0 - Invalid address causing the exception.</avrf:parameter1> <
avrf:parameter2>54d881 - Code address executing the invalid access.</avrf:parameter2> <
avrf:parameter3>16d858 - Exception record.</avrf:parameter3> <
avrf:parameter4>16d874 - Context record.</avrf:parameter4> -
<avrf:stackTrace> <avrf:trace>vrfcore!VfCoreRedirectedStopMessage+81 (d:\avrf\source\base\avrf\avrf30\vrfcore\stopredirect.cpp @ 103)<
/avrf:trace> <avrf:trace>vfbasics!VerifierStopMessage+292 (d:\avrf\source\base\avrf\avrf30\providers\basics\basics.c @ 1214)<
/avrf:trace> <avrf:trace>vfbasics!AVrfpCheckFirstChanceException+c8 (d:\avrf\source\base\avrf\vrfcommon\support.c @ 1108)<
/avrf:trace> <avrf:trace>vfbasics!AVrfpVectoredExceptionHandler+16 (d:\avrf\source\base\avrf\vrfcommon\support.c @ 323)<
/avrf:trace> <avrf:trace>ntdll!DbgPrint+57 ( @ 0)</avrf:trace> <avrf:trace>ntdll!RtlMultiAppendUnicodeStringBuffer+26f ( @ 0)<
/avrf:trace> <avrf:trace>ntdll!RtlMultiAppendUnicodeStringBuffer+321 ( @ 0)<
/avrf:trace> <avrf:trace>ntdll!KiUserExceptionDispatcher+f ( @ 0)<
/avrf:trace> <avrf:trace>RTSTowers!cXMeshParser::CreateSkinnedMesh+3af (c:\gamelib2\dx10meshloader.cpp @ 2816)<
/avrf:trace> <avrf:trace>RTSTowers!RTSLoadGraphic+229 (c:\gamelib2\assetmanager.cpp @ 68)<
/avrf:trace> <avrf:trace>RTSTowers!cRTSTower::RTSTower_INIT+16d (c:\gamelib2\rtstower.cpp @ 89)<
/avrf:trace> <avrf:trace>RTSTowers!cRTSTower::ConvertInitStrucToLibraryIndexs+162 (c:\gamelib2\rtstower.cpp @ 2436)<
/avrf:trace> <avrf:trace>RTSTowers!cAssetManager::ConvertObjectTypesToLibraryIndexes+6e (c:\gamelib2\assetmanager.cpp @ 918)<
/avrf:trace> <avrf:trace>RTSTowers!MyAppWin::LoadBackGround+c4a (c:\my3dgames\rtstowers\rtstowers\main.cpp @ 2604)<
/avrf:trace> <avrf:trace>RTSTowers!MyAppWin::LoadGameData+44 (c:\my3dgames\rtstowers\rtstowers\main.cpp @ 4316)<
/avrf:trace> <avrf:trace>RTSTowers!MyAppWin::Render+638 (c:\my3dgames\rtstowers\rtstowers\main.cpp @ 1544)<
/avrf:trace> <avrf:trace>RTSTowers!WinMain+147 (c:\my3dgames\rtstowers\rtstowers\main.cpp @ 941)<
/avrf:trace> <avrf:trace>RTSTowers!__tmainCRTStartup+260 (f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 547)<
/avrf:trace> <avrf:trace>RTSTowers!WinMainCRTStartup+f (f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 371)<
/avrf:trace> <avrf:trace>KERNEL32!BaseThreadInitThunk+12 ( @ 0)</avrf:trace> <avrf:trace>ntdll!RtlInitializeExceptionChain+63 ( @ 0)<
/avrf:trace> <avrf:trace>ntdll!RtlInitializeExceptionChain+36 ( @ 0)</avrf:trace> </avrf:stackTrace> </avrf:logEntry> </avrf:logSession> 
</avrf:logfile>
What kind of failure do you get exactly?

What does the code that calls CreateEnumObjects look like?

(edit)
0 - Invalid address causing the exception -- 0 here means it's a null pointer issue.
This is where the null pointer exception occurred, if you were running in visual studio, the debugger should've stopped here --
Function: cXMeshParser::CreateSkinnedMesh
File: c:\gamelib2\dx10meshloader.cpp
Line: 2816

Looks Like this

The HRESULT = -2005531807 = DXFILEERR_BADFILE But only when running the app verifier.

VC10.Did not break the code handles the error but it dose not load them.


BOOL cXParser::Parse(char *Filename, void **Data)
{
  IDirectXFile           *pDXFile = NULL;
  IDirectXFileEnumObject *pDXEnum = NULL;
  IDirectXFileData       *pDXData = NULL;

  // Error checking
  if(Filename == NULL)
    return FALSE;

  // Create the file object
  if(FAILED(DirectXFileCreate(&pDXFile)))
    return FALSE;

  // Register the common templates
  if(FAILED(pDXFile->RegisterTemplates(                       
                     (LPVOID)D3DRM_XTEMPLATES,                
                     D3DRM_XTEMPLATE_BYTES))) {
    pDXFile->Release();
    return FALSE;
  }

  // Create an enumeration object
  if(FAILED(pDXFile->CreateEnumObject((LPVOID)Filename,       
                                      DXFILELOAD_FROMFILE,    
                                      &pDXEnum))) {
    pDXFile->Release();
    return FALSE;
  }
  
  // Call the begin parse function, continuing if allowed
  if(BeginParse(Data) == TRUE) {

    // Loop through all top-level objects, breaking on errors
    BOOL ParseResult;
    while(SUCCEEDED(pDXEnum->GetNextDataObject(&pDXData))) {
      ParseResult = ParseObject(pDXData, NULL, 0, Data, FALSE);
      SAFE_RELEASE(pDXData);
      if(ParseResult == FALSE)
        break;
    }
  }

  // Call end parse function
  EndParse(Data);

  // Release used COM objects
  SAFE_RELEASE(pDXEnum);
  SAFE_RELEASE(pDXFile);

  return TRUE;
}

I looked in to the CreateSkinnedMesh Function and I found some suss code here .

the weights parser class

class cParserWeights

{

//weights have the following in .X files

//STRING transformNodeName;

//DWORD nWeights;

// array DWORD vertexIndices[nWeights];

//array float weights[nWeights];

// Matrix4x4 matrixOffset

std::vector<DWORD> VertexIndices;

};

Then In CreateSkinnedMesh I was using it like this

skinptr->AddBoneInfluences(bone,//the bone to set

m_SkinWeights[bone].VertexIndices.size(),// Number of vertices to add to the bone's influence.

(UINT *)&m_SkinWeights[bone].VertexIndices[0],//********HERE NOTICE THE (UINT *) Cast Very Bad I think********

//Pointer to an array of vertex indices. Each member of this array has a corresponding member

//in pWeights, such that pIndices corresponds to pWeights. The corresponding value in

//pWeights determines how much influence BoneIndex will have on the vertex indexed by pIndices.

//The size of the pIndices array must be equal to or greater than InfluenceCount.

&m_SkinWeights[bone].Weights[0]);// Pointer to an array of bone weights.

after changing the DWORD to a UINT I now get a out of memory error

//this may now be reflecting the real error dont no but.

What part is running out of memory is the question.


First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd1d4..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd4c0..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd608..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd720..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd838..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd73c..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd1d4..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd4c0..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd608..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd720..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd838..
First-chance exception at 0x760dfd1e in RTSTowers.exe: Microsoft C++ exception: _com_error at memory location 0x001cd73c..
D3D10: ERROR: ID3D10Device::CreateBuffer: CreateBuffer returning E_OUTOFMEMORY, meaning memory was exhausted. [ STATE_CREATION ERROR #70: CREATEBUFFER_OUTOFMEMORY_RETURN ]

This topic is closed to new replies.

Advertisement