Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen::Vec2 is misaligned but condition cannot check it. #97

Open
recsater opened this issue Jul 11, 2024 · 0 comments
Open

Eigen::Vec2 is misaligned but condition cannot check it. #97

recsater opened this issue Jul 11, 2024 · 0 comments

Comments

@recsater
Copy link

Eigen::Vec3, Eigen:: Mat3 and so on is ok except Eigen::Vec2

Make Eigen formattable

include "eigen3/Eigen/Core"

#define _FMTLOG_EIGEN_FORMAT(_Scalar, _Rows, _Cols)                          \
  template <>                                                                \
  struct fmt::formatter<Eigen::Matrix<_Scalar, _Rows, _Cols>>                \
      : formatter<std::string_view> {                                        \
                                                                             \
    auto format(const Eigen::Matrix<_Scalar, _Rows, _Cols>& c,               \
                format_context& ctx) const {                                 \
      std::stringstream ss;                                                  \
      ss << c.format(Eigen::IOFormat(5, 0, ", ", "\n", "[", "]", "[", "]")); \
      return fmt::formatter<fmt::string_view>::format(ss.str(), ctx);        \
    }                                                                        \
  };

_FMTLOG_EIGEN_FORMAT(double, -1, -1)
_FMTLOG_EIGEN_FORMAT(double, 2, -1)
_FMTLOG_EIGEN_FORMAT(double, 2, 1)
_FMTLOG_EIGEN_FORMAT(double, 2, 2)
_FMTLOG_EIGEN_FORMAT(double, 3, -1)
_FMTLOG_EIGEN_FORMAT(double, 3, 1)
_FMTLOG_EIGEN_FORMAT(double, 3, 2)
_FMTLOG_EIGEN_FORMAT(double, 3, 3)
_FMTLOG_EIGEN_FORMAT(double, 4, -1)
_FMTLOG_EIGEN_FORMAT(double, 4, 1)
_FMTLOG_EIGEN_FORMAT(double, 4, 2)
_FMTLOG_EIGEN_FORMAT(double, 4, 3)
_FMTLOG_EIGEN_FORMAT(double, 4, 4)
logi("{}", Eigen::Mat3); // OK
logi("{}", Eigen::Vec2); // Segfault

Segfault

// fmtlog.h :487
    if constexpr (std::is_trivially_copyable_v<fmt::remove_cvref_t<Arg>>) { // false for Eigen::Vec2 
        memcpy(out, &arg, sizeof(Arg)); // If run this line, formatting is successful.
      }
      else {
        new (out) fmt::remove_cvref_t<Arg>(std::forward<Arg>(arg));
      }
    return encodeArgs<CstringIdx>(cstringSize, out + sizeof(Arg), std::forward<Args>(args)...); // Segfault at this line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant