Backends: DX12: Let user specifies an optional custom error handling function by setting ImGui_ImplDX12_InitInfo::CheckHrResultFn #9026
+196
−107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add optional CheckHrResultFn member to ImGui_ImplDX12_InitInfo for custom error handling, matching Vulkan backend. Also fix a couple of missing error checks.
In the example file, I changed CreateDeviceD3D to return HRESULT instead of bool, preserving existing error and cleanup logic. However, I think direct error checks and early aborts would be better here. It would simplify the code and cleanup is not handled properly anyway and is very difficult to manage without RAII.
To be clear, I suggest replacing this:
HRESULT hr = CreateDeviceD3D(hwnd); if (FAILED(hr)) { CleanupDeviceD3D(); ::UnregisterClassW(wc.lpszClassName, wc.hInstance); check_hr_result(hr); } [...] HRESULT CreateDeviceD3D(HWND hWnd) { [...] HRESULT hr = D3D12CreateDevice(nullptr, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)); if (FAILED(hr)) return hr; [...] }By this:
If you agree, I will make these changes.