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

win32 dx12 crashes #3121

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/imgui_impl_dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,8 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
desc.NodeMask = 1;

IM_ASSERT(g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&data->RtvDescHeap)) == S_OK);
HRESULT hr = g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&data->RtvDescHeap));
IM_ASSERT(hr == S_OK);

SIZE_T rtv_descriptor_size = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = data->RtvDescHeap->GetCPUDescriptorHandleForHeapStart();
Expand Down Expand Up @@ -847,6 +848,16 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport)
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
if (ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData)
{
//Wait for pending operations to complete to safely release objects below
HRESULT hr;
if (data->CommandQueue && data->Fence && data->FenceEvent)
{
hr = data->CommandQueue->Signal(data->Fence, ++data->FenceSignaledValue); IM_ASSERT(hr == S_OK);
WaitForSingleObject(data->FenceEvent, 0); // reset any forgotten waits
hr = data->Fence->SetEventOnCompletion(data->FenceSignaledValue, data->FenceEvent); IM_ASSERT(hr == S_OK);
WaitForSingleObject(data->FenceEvent, INFINITE);
}

SafeRelease(data->CommandQueue);
SafeRelease(data->CommandList);
SafeRelease(data->SwapChain);
Expand Down