Skip to content

Commit

Permalink
Fix crash on systems where render GPU is not attached to the output d…
Browse files Browse the repository at this point in the history
…isplay (#170)
  • Loading branch information
sherief authored Mar 23, 2020
1 parent 3a8e821 commit 3b407fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/d3d11/d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "d3d11_device.hpp"
#include "d3d11_device_context.hpp"

extern thread_local bool inPresentCall;

HOOK_EXPORT HRESULT WINAPI D3D11CreateDevice(IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, ID3D11DeviceContext **ppImmediateContext)
{
LOG(INFO) << "Redirecting D3D11CreateDevice" << '('
Expand Down Expand Up @@ -59,6 +61,11 @@ HOOK_EXPORT HRESULT WINAPI D3D11CreateDeviceAndSwapChain(IDXGIAdapter *pAdapter,
return hr;
}

if (inPresentCall && !ppSwapChain)
{
return hr;
}

if (pFeatureLevel != nullptr) // Copy feature level value to application variable if the argument exists
*pFeatureLevel = FeatureLevel;

Expand Down
4 changes: 4 additions & 0 deletions source/dxgi/dxgi_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "d3d12/runtime_d3d12.hpp"
#include <algorithm>

thread_local bool inPresentCall = false;

DXGISwapChain::DXGISwapChain(D3D10Device *device, IDXGISwapChain *original, const std::shared_ptr<reshade::runtime> &runtime) :
_orig(original),
_interface_version(0),
Expand Down Expand Up @@ -276,10 +278,12 @@ HRESULT STDMETHODCALLTYPE DXGISwapChain::GetDevice(REFIID riid, void **ppDevice)

HRESULT STDMETHODCALLTYPE DXGISwapChain::Present(UINT SyncInterval, UINT Flags)
{
inPresentCall = true;
runtime_present(Flags);

const HRESULT hr = _orig->Present(SyncInterval, Flags);
handle_runtime_loss(hr);
inPresentCall = false;
return hr;
}
HRESULT STDMETHODCALLTYPE DXGISwapChain::GetBuffer(UINT Buffer, REFIID riid, void **ppSurface)
Expand Down

0 comments on commit 3b407fd

Please sign in to comment.