diff --git a/examples/renderlib/rendering/d3d11.cpp b/examples/renderlib/rendering/d3d11.cpp index 03598350..6671a696 100644 --- a/examples/renderlib/rendering/d3d11.cpp +++ b/examples/renderlib/rendering/d3d11.cpp @@ -59,6 +59,12 @@ bool D3D11::initialize() { } void D3D11::render_imgui() { + auto draw_data = ImGui::GetDrawData(); + + if (draw_data == nullptr) { + return; + } + ComPtr context{}; float clear_color[]{0.0f, 0.0f, 0.0f, 0.0f}; @@ -67,14 +73,23 @@ void D3D11::render_imgui() { device->GetImmediateContext(&context); context->ClearRenderTargetView(this->rt_rtv.Get(), clear_color); context->OMSetRenderTargets(1, this->rt_rtv.GetAddressOf(), NULL); - ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + ImGui_ImplDX11_RenderDrawData(draw_data); // Set the back buffer to be the render target. context->OMSetRenderTargets(1, this->bb_rtv.GetAddressOf(), nullptr); - ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + ImGui_ImplDX11_RenderDrawData(draw_data); } void D3D11::render_imgui_vr(ID3D11DeviceContext* context, ID3D11RenderTargetView* rtv) { + if (context == nullptr || rtv == nullptr) { + return; + } + + auto draw_data = ImGui::GetDrawData(); + if (draw_data == nullptr) { + return; + } + context->OMSetRenderTargets(1, &rtv, NULL); - ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + ImGui_ImplDX11_RenderDrawData(draw_data); } diff --git a/examples/renderlib/rendering/d3d12.cpp b/examples/renderlib/rendering/d3d12.cpp index d9f6df99..8fb4a561 100644 --- a/examples/renderlib/rendering/d3d12.cpp +++ b/examples/renderlib/rendering/d3d12.cpp @@ -118,7 +118,13 @@ bool D3D12::initialize() { return true; } -void D3D12::render_imgui() { +void D3D12::render_imgui() { + auto draw_data = ImGui::GetDrawData(); + + if (draw_data == nullptr) { + return; + } + auto& cmd = this->cmds[this->frame_count++ % this->cmds.size()]; if (cmd.fence_event != nullptr && cmd.fence != nullptr && cmd.fence->GetCompletedValue() < cmd.fence_value) { @@ -166,7 +172,7 @@ void D3D12::render_imgui() { rts[0] = this->get_cpu_rtv(device, (D3D12::RTV)bb_index); cmd.list->OMSetRenderTargets(1, rts, FALSE, NULL); cmd.list->SetDescriptorHeaps(1, this->srv_desc_heap.GetAddressOf()); - ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), cmd.list.Get()); + ImGui_ImplDX12_RenderDrawData(draw_data, cmd.list.Get()); barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT; cmd.list->ResourceBarrier(1, &barrier);