title: GTSAM Segfault - possible alignment issue?
body: <p>I am trying to use <a href="https://gtsam.org/" rel="nofollow noreferrer">GTSAM</a>. I have the following sample class:</p>
  <h3>GraphManager.h</h3>
  <pre><code>#pragma once
  
  #include &lt;gtsam/navigation/CombinedImuFactor.h&gt;
  
  using namespace gtsam;
  
  class GraphManager
  {
  public:
      GraphManager();
  
  
  private:
      std::shared_ptr&lt;PreintegratedCombinedMeasurements&gt; preint;
  };
  </code></pre>
  <h3>GraphManager.cpp</h3>
  <pre><code>#include &lt;gtsam_fusion/GraphTest.h&gt;
  
  GraphTest::GraphTest()
  {
      auto imuParams = PreintegratedCombinedMeasurements::Params::MakeSharedD();
      preint = std::make_shared&lt;PreintegratedCombinedMeasurements&gt;(imuParams);
  }
  </code></pre>
  <p>And the following gtest case:</p>
  <pre><code>#include &lt;gtsam_fusion/GraphManager.h&gt;
  
  #include &lt;gtest/gtest.h&gt;
  #include &lt;iostream&gt;
  
  
  TEST(GraphManagerTest, test1)
  {
      VILFusion::GraphManager manager;
  
      EXPECT_TRUE(false) &lt;&lt; &quot;1&quot;; // This is just here to prove that `manager` was constructed.
  }
  
  int main(int argc, char *argv[])
  {
      testing::InitGoogleTest(&amp;argc, argv);
      return RUN_ALL_TESTS();
  }
  </code></pre>
  <p>When I run the test, I do get the &quot;1&quot; message, so I know the <code>GraphManager</code> object has been successfully initialized. However, after that, the test case segfaults. Through debugging, I think this is happening in the destructor of the <code>preint</code> shared pointer, but I don't have enough experience with debugging to know for sure.</p>
  <p>Here's what I find strange: If I move the implementation of <code>GraphManager</code>'s constructor into the header file, it no longer segfaults. As I was deleting code to get to this minimum viable example, it would sometimes work, seemingly at random, even though the code I was deleting had nothing to do with the <code>preint</code> shared pointer.</p>
  <p>I found <a href="https://gtsam-jlblanco-docs.readthedocs.io/en/latest/_static/doxygen/html/namespacegtsam.html#a3ec36279b8211b98545e338ac5371b8c" rel="nofollow noreferrer">this <code>gtsam::make_shared</code> function</a> in the GTSAM documentation, which seems to indicate that alignment may be an issue. This also fits my observation that changing unrelated code could make the segfault appear and disappear. However, in <a href="https://github.com/borglab/gtsam/blob/6425000775da29c93719f37dce3f2de38a0064ec/examples/ImuFactorsExample.cpp#L184-L191" rel="nofollow noreferrer">this example code</a> from GTSAM, the special <code>gtsam::make_shared</code> function is not used for <code>PreintegratedCombinedMeasurements</code>. Is this example incorrect, and only runs by chance? Or is the <code>gtsam::make_shared</code> function not necessary here, and alignment is not actually the issue? Is there more documentation on when and how I should use the special <code>gtsam::make_shared</code> function?</p>
  <p>If it matters: I am doing this within the context of a ROS node, so I am using catkin as my build system. However, this issue occurs without referencing ROS or using any ROS libraries in the code at all.</p>
  <p><strong>Update</strong>: The problem still persists if I ditch the shared pointer altogether, and simply make <code>preint</code> of type <code>PreintegratedCombinedMeasurements</code>.</p>