Skip to content

Commit

Permalink
Fix failed assert in XrMath.h (#110)
Browse files Browse the repository at this point in the history
Fixed issue #109. The error occurred in VS2022 but not in the VS2019 toolset.

The compiler error message isn't as obvious now but I added a comment if anyone tries to use xr::math::cast for a type that hasn't added a template specialization.
  • Loading branch information
Darryl Gough authored Aug 19, 2022
1 parent e1a3b69 commit ef75946
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions shared/XrUtility/XrMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ namespace xr::math {
NearFar NearFar;
};

// Type conversion between math types
// Type conversion between math types.
// If you get the error "attempting to reference a deleted function" then you need to implement
// xr::math::detail::implement_math_cast for types X and Y. See examples further down.
template <typename X, typename Y>
constexpr const X& cast(const Y& value);
constexpr const X& cast(const Y& value) = delete;

// Convert XR types to DX
DirectX::XMVECTOR XM_CALLCONV LoadXrVector2(const XrVector2f& vector);
Expand Down Expand Up @@ -105,13 +107,6 @@ namespace xr::math {
}
} // namespace detail

#ifdef _MSC_VER
template <typename X, typename Y>
constexpr const X& cast(const Y& value) {
static_assert(false, "Undefined cast from Y to type X");
}
#endif

#define DEFINE_CAST(X, Y) \
template <> \
constexpr const X& cast<X, Y>(const Y& value) { \
Expand Down

0 comments on commit ef75946

Please sign in to comment.