Skip to content
Permalink
Browse files
Fix crash on systems where render GPU is not attached to the output d…
…isplay (#170)
  • Loading branch information
sherief committed Mar 23, 2020
1 parent 3a8e821 commit 3b407fdafca0e87dd101a9d84c6802ee8a5b6d86
Showing 2 changed files with 11 additions and 0 deletions.
@@ -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" << '('
@@ -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;

@@ -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),
@@ -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)

0 comments on commit 3b407fd

Please sign in to comment.