title: Heap corruption at class constructor when allocated dynamically
body: <p>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.</p>
  
  <p>This is the code that creates my scene and causes the heap corruption:</p>
  
  <pre><code>tetraRender::Camera cam(600.0f, 800.0f, 0.75f);
  _ASSERT(_CrtCheckMemory());
  //CORRUPTION HAPPENS IN THE NEXT LINE
      std::shared_ptr&lt;tetraRender::Scene&gt;  scene(new tetraRender::Scene(cam));
  </code></pre>
  
  <p>until that part of the code no dynamic allocation was done by me. And the constructor of the Scene starts like this:</p>
  
  <pre><code>    tetraRender::Scene::Scene(Camera cam)
  {
      _ASSERT(_CrtCheckMemory());
      setCamera(cam);
      light.intensity = 1.0f;
  </code></pre>
  
  <p>the assert fails, and from what I read the heap memory that is beeing written over is the memory of the scene beeing built.</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>And looking at the heap:</p>
  
  <blockquote>
    <p>TetraVisu.exe!tetraRender::Scene  1   624</p>
  </blockquote>
  
  <p>and:</p>
  
  <blockquote>
    <p>&lt;0x1831FD719A0>   0x000001831fd719a0 {cam={lookAt={value=0x000001831fd719a0 {{x=1.00000000 y=0.000000000 z=0.000000000 ...}, ...} } ...} ...} 624</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>I know heap issues are hard to figure out that's why I need someone with a better understanding of C++ than me.</p>
  
  <p>EDIT: Also the Scene and camera objects come from a statically linked library I made, I don't know if this can help.</p>