diff options
Diffstat (limited to 'dxg/dxcommon.ixx')
| -rw-r--r-- | dxg/dxcommon.ixx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/dxg/dxcommon.ixx b/dxg/dxcommon.ixx new file mode 100644 index 0000000..b06ae95 --- /dev/null +++ b/dxg/dxcommon.ixx | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <wrl.h> | ||
| 4 | #include <stdexcept> | ||
| 5 | |||
| 6 | export module dxcommon; | ||
| 7 | |||
| 8 | using Microsoft::WRL::ComPtr; | ||
| 9 | |||
| 10 | namespace dx { | ||
| 11 | |||
| 12 | export { | ||
| 13 | |||
| 14 | class exception : public std::exception | ||
| 15 | { | ||
| 16 | public: | ||
| 17 | exception() noexcept = default; | ||
| 18 | |||
| 19 | exception(HRESULT result, const char* file, int line) noexcept | ||
| 20 | { | ||
| 21 | sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X", | ||
| 22 | file, line, static_cast<unsigned int>(result)); | ||
| 23 | } | ||
| 24 | |||
| 25 | exception(const char* error, const char* file, int line) noexcept | ||
| 26 | { | ||
| 27 | sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error); | ||
| 28 | } | ||
| 29 | |||
| 30 | [[nodiscard]] const char* what() const noexcept final | ||
| 31 | { | ||
| 32 | return m_error; | ||
| 33 | } | ||
| 34 | |||
| 35 | private: | ||
| 36 | static thread_local char m_error[1024]; | ||
| 37 | }; | ||
| 38 | |||
| 39 | template <typename T> | ||
| 40 | void SafeRelease(ComPtr<T>& ptr) | ||
| 41 | { | ||
| 42 | if (ptr) | ||
| 43 | { | ||
| 44 | ptr->Release(); | ||
| 45 | ptr = nullptr; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | } // export | ||
| 50 | |||
| 51 | thread_local char exception::m_error[1024]; | ||
| 52 | |||
| 53 | } // dx | ||
