0

I am trying to use ImGuizmo and I am running into a bizarre situation.

Inside the main cpp file of the library there is this function:

 static void ComputeCameraRay(vec_t& rayOrigin, vec_t& rayDir, ImVec2 position = ImVec2(gContext.mX, gContext.mY), ImVec2 size = ImVec2(gContext.mWidth, gContext.mHeight))
   {
      ImGuiIO& io = ImGui::GetIO();

      matrix_t mViewProjInverse;
      mViewProjInverse.Inverse(gContext.mViewMat * gContext.mProjectionMat);

      const float mox = ((io.MousePos.x - position.x) / size.x) * 2.f - 1.f;
      const float moy = (1.f - ((io.MousePos.y - position.y) / size.y)) * 2.f - 1.f;

      const float zNear = gContext.mReversed ? (1.f - FLT_EPSILON) : 0.f;
      const float zFar = gContext.mReversed ? 0.f : (1.f - FLT_EPSILON);

      rayOrigin.Transform(makeVect(mox, moy, zNear, 1.f), mViewProjInverse);
      rayOrigin *= 1.f / rayOrigin.w;
      vec_t rayEnd;
      rayEnd.Transform(makeVect(mox, moy, zFar, 1.f), mViewProjInverse);
      rayEnd *= 1.f / rayEnd.w;
      rayDir = Normalized(rayEnd - rayOrigin);
   }

Pay attention to the io variable. I have stepped through the function using gdb. I get this:

(gdb) p ImGui::GetIO().MousePos.x
$8 = 73


(gdb) p io.MousePos.x
$9 = 0

How is this possible? Yes io is a reference so something could overwrite its value, but it's a reference to the object returned by ImGui::GetIO(). They should be identical. How is this possible?

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • Do you happen to link together multiple different static libraries / object files that each contain ImGui's global IO variable? You might have multiple copies of it in that case. – Jonathan S. May 04 '22 at 20:51
  • Yup I just ofund out the issue, answering the question – Makogan May 04 '22 at 21:12

1 Answers1

0

This was happening because I miss configured my build system, I was using the headers of one version of imgui but the binaries of another, thus the memory was unaligned.

Makogan
  • 8,208
  • 7
  • 44
  • 112