title: Segfault in shared_ptr destructor
body: <h3>Context</h3>
  
  <p>I am trying to make a small game engine and currently I'm working on an entity component system. I have an array of shared pointers to Model objects (3D models read from OBJ files). I then connect the models with entities using a model component that essentially has a struct of two arrays, one with entity handles and the other with indices to models. The indices refer to elements of a vector in the component with the actual shared pointers to the models. I do this to not have to construct the shared pointers in dynamically allocated memory.</p>
  
  <p>I have two classes for models, base class <code>Model</code> and a specialised subclass <code>UntexturedModel</code> that stores the vertex position data in a more efficient way. For testing I am now using two entities and assigning the first one a <code>Model</code> object and the other <code>UntexturedModel</code> object (to make sure both behave correctly with this system).</p>
  
  <h3>Problem</h3>
  
  <p>The actual component behaviour works as intended, the model is correctly connected with the entity and retrieved when rendering. But when the <code>main</code> function terminates, there is a segfault. I used Valgrind to try and figure out where the problem was, and it says there is an Invalid Jump from <code>std::default_delete&lt;Model&gt;::operator()(Model*)</code>.</p>
  
  <p>I have tried creating a separate shared pointer of the exact same type and resetting it immediately, which AFAIK should trigger the same problem, but it goes through smoothly. After a couple similar tests (using only the base class model, using only one model for both entities, adding a custom deleter that calls <code>~Model</code> and then deletes the pointer) I am fairly certain that the problem only occurs after the <code>main</code> function terminates.</p>
  
  <p>I can add any code snippets, just ask which ones.</p>