title: Memory Allocation Crash
body: <p>I have stumbled accross a strange problem in which I cannot understand. I am not an expert at C/C++ so bear with me. I have an NPC class, which derives from a Player class, which derives from a Sprite class. The sprite class contains a setupAnimation function, which allocates an array of floats containing coordinates on the texture, each element of the array refers to a frame of animation. This is all good and works fine.</p>
  
  <p>However, a problem occurs when I add an array of pointers to the NPC class. These pointers are of an Item class type. When I add this array, it works fine if the array is small (10 was the size I tested), but will crash when allocating the array of floats for texture coordinates mentioned earlier if the size is a bit larger (100 was the size I tested).</p>
  
  <p>Here are some code fragments showing the material I mentioned above:</p>
  
  <p>The Item class array of pointers:</p>
  
  <pre><code>    engItem* itsLoot[100]; // With 100 here, the crash occurs as shown below
  </code></pre>
  
  <p>The texture coordinates and their allocation counterparts:</p>
  
  <pre><code>    GLfloat* itsTextureXData;
      GLfloat* itsTextureYData;
  
      ...
  
      animationFile &gt;&gt; frameCount; // Tested, the value is correct
  
      engDeallocate(getTextureXData(), true); // Works fine
      itsTextureXData = new GLfloat[frameCount]; // This is where the crash occurs
  
      engDeallocate(getTextureYData(), true);
      itsTextureYData = new GLfloat[frameCount];
  </code></pre>
  
  <p>This fragment of code is the basis of every class that derives from the Sprite class. What I can't understand is why an extra 90 pointers causes a problem during the float allocation. Just a bit of software information to go with this</p>
  
  <p>OS: Windows Vista 32-bit, Compiler: Visual C++ 9.0, Program runtime memory: ~17,600k, System memory: ~2GB</p>
  
  <p>With this in mind, I can't see it being memory running dry, and I can't tie in how an array of pointers causes the allocation to fail. As mentioned, the allocation works fine in all other classes derived from Sprite (as well as Sprite itself), but once this array of pointers is added the the NPC class, the NPC will no longer allocate this texture data float array without crashing.</p>