Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
hresult.h
Go to the documentation of this file.
1// hresult.h — HRESULT の失敗を「呼んだ式・ファイル:行・エラー名と意味」つきでログに出す(T-0007)。
2//
3// 使い方:
4// if (!BICAMERAL_CHECK_HR(Channel::Gpu, device->CreateCommittedResource(...))) return false;
5// → [ 0.120] E gpu | device->CreateCommittedResource(...) が失敗: E_OUTOFMEMORY (0x8007000E): ... (gpu.cpp:42)
6//
7// 失敗して当然の問い合わせ(古いランタイムでの CheckFeatureSupport など)にはマクロを使わず、
8// DescribeHresult() で説明を作って Warning や Info で出す(Error はバグか環境の問題だけにする)。
9// windows.h を include しないため、HRESULT と同じ型(long)を HResult として受け取る。
10#pragma once
11
12#include <source_location>
13#include <string>
14#include <string_view>
15
16#include "core/log.h"
17
18namespace bicameral {
19
20 using HResult = long; // HRESULT と同じ型(hresult.cpp で static_assert している)
21
22 // "E_INVALIDARG (0x80070057): パラメーターが間違っています。" の形。名前を知らないコードは 16 進だけ
23 [[nodiscard]] std::string DescribeHresult(HResult result);
24
25 // 成功なら true。失敗なら Level::Error でログを出して false。場所は呼んだ所になる
26 [[nodiscard]] bool CheckHresult(HResult result, Channel channel, std::string_view expression,
27 const std::source_location& location = std::source_location::current());
28
29} // namespace bicameral
30
31// 式を文字列にしてログに残すためにマクロにしている(関数では呼んだ API 名を手で書くことになり、ずれうる。ADR-0006)
32#define BICAMERAL_CHECK_HR(channel, expression) ::bicameral::CheckHresult((expression), (channel), #expression)
bool CheckHresult(HResult result, Channel channel, std::string_view expression, const std::source_location &location)
Definition hresult.cpp:99
long HResult
Definition hresult.h:20
Channel
Definition log.h:38
std::string DescribeHresult(HResult result)
Definition hresult.cpp:88