Array pointer data being cleared in between function calls without an explicit command? : <p>I have the following issue:</p>

<p>In a C++ program I have a global data structure declared as <code>Renderer Rendering_Handler</code>, which contains a member field defined as <code>vector&lt;Render_Info&gt; visble objects</code>.</p>

<p>What the data structures themselves are doing is not important, they are wrappers needed to abstract data to parallelize my program.</p>

<p>To be clear, Rendering_Handler is completely global, and it's in fact a singleton (I can 100% confirm that the constructor has been called once and only once for this class).</p>

<p>I have declared the following class method:</p>

<pre><code>Render_Info* Renderer::add_Render_Info()
{
    visible_objects.push_back(Render_Info());
    return &amp;(visible_objects.back());
}
</code></pre>

<p>Simple enough, it creates a new <code>Render_Info</code> structure, appends it to the <code>visible_objects</code> array and returns a pointer to the object.</p>

<p>A different data structure called <code>Chunk</code> has a constructor defined as</p>

<pre><code>Chunk::Chunk(vec3 offset, World* w) 
{
    /*initialize some values*/

    draw_info = Rendering_Handler-&gt;add_Render_Info();
    draw_info-&gt;VBOs = vector&lt;GLuint&gt;(5);

    /*initialize OpenGL VAOs, VBOs and other buffer objects*/

    cout &lt;&lt; draw_info-&gt;VBOs.size() &lt;&lt; endl;
    cout &lt;&lt; draw_info &lt;&lt; endl;
}
</code></pre>

<p>It also has a method defined as:</p>

<pre><code>void Chunk::update_render_info()
{
    cout &lt;&lt; draw_info-&gt;VBOs.size() &lt;&lt; endl;
    cout &lt;&lt; draw_info &lt;&lt; endl;

    /*OpenGL stuff*/

}
</code></pre>

<p>And finally</p>

<p>We have the method that initializes everything:</p>

<pre><code>World::World()
{   
    /*Initialize chunks in a circular 3D array*/
    loaded_chunks = new Chunk_Holder(h_radius, h_radius, v_radius, this);

    for(int i=0; i&lt;h_radius; i++)
    {
        for(int j=0; j&lt;h_radius; j++)
        {
            for(int k=0; k&lt;v_radius; k++)
            {
               (*loaded_chunks)(i,j,k)-&gt;update();
            }
        }
    }
}
</code></pre>

<p>The output of the rpgram is:</p>

<p><a href="https://i.stack.imgur.com/NUqLm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NUqLm.png" alt="enter image description here"></a></p>

<p>...</p>

<p><a href="https://i.stack.imgur.com/6xbPY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6xbPY.png" alt="enter image description here"></a></p>

<p>Let's focus on the frist 2 and last 2 lines of the output, which correspond to the print statements I have added for debugging.</p>

<p>The first 2 lines indicate that 5 elements have been added to the buffer at location 0x556edb7ae200</p>

<p>The last 2 lines tell me that the same buffer (same since the memory location is the same) now contains 0 elements.</p>

<p>As you can see from the snaps of the code, no function is called in between creating the Chunks and updating them. Does anybody have an idea of what could be causing the dissapearance of these elements? </p>

<p>Have I not correctly reserved the memory? Are these objects being cleared without my knowledge due to wrong allocation?</p>
