Skip to content

Commit

Permalink
D3D12: Fix for case when swapchain could be recreated
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 10, 2023
1 parent 458d6e4 commit a78ced4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/hooks/D3D12Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,22 @@ HRESULT WINAPI D3D12Hook::present(IDXGISwapChain3* swap_chain, UINT sync_interva
}

if (!d3d12->m_is_phase_1 && swap_chain != d3d12->m_swapchain_hook->get_instance()) {
return present_fn(swap_chain, sync_interval, flags);
const auto og_instance = d3d12->m_swapchain_hook->get_instance();

// If the original swapchain instance is invalid, then we should not proceed, and rehook the swapchain
if (IsBadReadPtr(og_instance, sizeof(void*)) || IsBadReadPtr(og_instance.deref(), sizeof(void*))) {
spdlog::error("Bad read pointer for original swapchain instance, re-hooking");
d3d12->m_is_phase_1 = true;
}

if (!d3d12->m_is_phase_1) {
return present_fn(swap_chain, sync_interval, flags);
}
}

if (d3d12->m_is_phase_1) {
//d3d12->m_present_hook.reset();
d3d12->m_swapchain_hook.reset();

// vtable hook the swapchain instead of global hooking
// this seems safer for whatever reason
Expand Down

0 comments on commit a78ced4

Please sign in to comment.