I have a problem that I have a really hard time figuring out. The program this happened on is a bit big so I'm going to try to put only the relevant pieces of code hoping it's enough.
This is the code that creates my scene and causes the heap corruption:
tetraRender::Camera cam(600.0f, 800.0f, 0.75f);
_ASSERT(_CrtCheckMemory());
//CORRUPTION HAPPENS IN THE NEXT LINE
std::shared_ptr<tetraRender::Scene> scene(new tetraRender::Scene(cam));
until that part of the code no dynamic allocation was done by me. And the constructor of the Scene starts like this:
tetraRender::Scene::Scene(Camera cam)
{
_ASSERT(_CrtCheckMemory());
setCamera(cam);
light.intensity = 1.0f;
the assert fails, and from what I read the heap memory that is beeing written over is the memory of the scene beeing built.
HEAP CORRUPTION DETECTED: after Normal block (#1735) at 0x000001831FD719A0. CRT detected that the application wrote to memory after end of heap buffer. Normal located at 0x000001831FD719A0 is 624 bytes long.
And looking at the heap:
TetraVisu.exe!tetraRender::Scene 1 624
and:
<0x1831FD719A0> 0x000001831fd719a0 {cam={lookAt={value=0x000001831fd719a0 {{x=1.00000000 y=0.000000000 z=0.000000000 ...}, ...} } ...} ...} 624
I don't know how to debug this because it seems as soon as I allocate this object my heap gets corrupted as soon as the constructor starts. I tried allocating other objects and it goes fine. It appears to happen only with Scene and when I have the member Camera shadowProjection.
I know heap issues are hard to figure out that's why I need someone with a better understanding of C++ than me.
EDIT: Also the Scene and camera objects come from a statically linked library I made, I don't know if this can help.
Ok, so the question was very far from having the right info for anyone to help. The issue seemed to pop in and out of existance at random. It would seem that it was because of a difference between the headers used to build the library and used to call the objects in the final code. I think this is why the heap was getting corrupted, the size was probably calculated differently.
I don't have the issue anymore so this is probably the reason.