Skip to content

Commit a6546e8

Browse files
committed
Fix crash in S.T.A.L.K.E.R.: Shadow of Chornobyl - Enhanced Edition
1 parent 3ecf7df commit a6546e8

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

source/d3d12/d3d12_device.cpp

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -313,28 +313,32 @@ HRESULT STDMETHODCALLTYPE D3D12Device::CreateCommandList(UINT nodeMask, D3D12_CO
313313
{
314314
assert(ppCommandList != nullptr);
315315

316-
const auto command_list_proxy = new D3D12GraphicsCommandList(this, static_cast<ID3D12GraphicsCommandList *>(*ppCommandList));
317-
318-
// Upgrade to the actual interface version requested here (and only hook graphics command lists)
319-
if (command_list_proxy->check_and_upgrade_interface(riid))
316+
// Ignore video command lists ('ID3D12VideoProcessCommandList', 'ID3D12VideoProcessCommandList', ...) in case they are created with the base 'ID3D12CommandList' interface
317+
if (type >= D3D12_COMMAND_LIST_TYPE_DIRECT && type <= D3D12_COMMAND_LIST_TYPE_COPY)
320318
{
321-
*ppCommandList = command_list_proxy;
319+
const auto command_list_proxy = new D3D12GraphicsCommandList(this, static_cast<ID3D12GraphicsCommandList *>(*ppCommandList));
320+
321+
// Upgrade to the actual interface version requested here (and only hook graphics command lists)
322+
if (command_list_proxy->check_and_upgrade_interface(riid))
323+
{
324+
*ppCommandList = command_list_proxy;
322325

323326
#if RESHADE_ADDON
324-
// Same implementation as in 'D3D12GraphicsCommandList::Reset'
325-
reshade::invoke_addon_event<reshade::addon_event::reset_command_list>(command_list_proxy);
327+
// Same implementation as in 'D3D12GraphicsCommandList::Reset'
328+
reshade::invoke_addon_event<reshade::addon_event::reset_command_list>(command_list_proxy);
326329
#endif
327330

328331
#if RESHADE_ADDON >= 2
329-
if (pInitialState != nullptr)
330-
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline>(command_list_proxy, reshade::api::pipeline_stage::all, to_handle(pInitialState));
332+
if (pInitialState != nullptr)
333+
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline>(command_list_proxy, reshade::api::pipeline_stage::all, to_handle(pInitialState));
331334
#endif
332-
}
333-
else // Do not hook object if we do not support the requested interface
334-
{
335-
reshade::log::message(reshade::log::level::warning, "Unknown interface %s in ID3D12Device::CreateCommandList.", reshade::log::iid_to_string(riid).c_str());
335+
}
336+
else // Do not hook object if we do not support the requested interface
337+
{
338+
reshade::log::message(reshade::log::level::warning, "Unknown interface %s in ID3D12Device::CreateCommandList.", reshade::log::iid_to_string(riid).c_str());
336339

337-
delete command_list_proxy; // Delete instead of release to keep reference count untouched
340+
delete command_list_proxy; // Delete instead of release to keep reference count untouched
341+
}
338342
}
339343
}
340344
#if RESHADE_VERBOSE_LOG
@@ -1218,30 +1222,34 @@ HRESULT STDMETHODCALLTYPE D3D12Device::EnqueueMakeResident(D3D12_RESIDENCY_FLAGS
12181222
return static_cast<ID3D12Device3 *>(_orig)->EnqueueMakeResident(Flags, NumObjects, ppObjects, pFenceToSignal, FenceValueToSignal);
12191223
}
12201224

1221-
HRESULT STDMETHODCALLTYPE D3D12Device::CreateCommandList1(UINT NodeMask, D3D12_COMMAND_LIST_TYPE Type, D3D12_COMMAND_LIST_FLAGS Flags, REFIID riid, void **ppCommandList)
1225+
HRESULT STDMETHODCALLTYPE D3D12Device::CreateCommandList1(UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, D3D12_COMMAND_LIST_FLAGS flags, REFIID riid, void **ppCommandList)
12221226
{
12231227
assert(_interface_version >= 4);
1224-
const HRESULT hr = static_cast<ID3D12Device4 *>(_orig)->CreateCommandList1(NodeMask, Type, Flags, riid, ppCommandList);
1228+
const HRESULT hr = static_cast<ID3D12Device4 *>(_orig)->CreateCommandList1(nodeMask, type, flags, riid, ppCommandList);
12251229
if (SUCCEEDED(hr))
12261230
{
12271231
assert(ppCommandList != nullptr);
12281232

1229-
const auto command_list_proxy = new D3D12GraphicsCommandList(this, static_cast<ID3D12GraphicsCommandList *>(*ppCommandList));
1230-
1231-
// Upgrade to the actual interface version requested here (and only hook graphics command lists)
1232-
if (command_list_proxy->check_and_upgrade_interface(riid))
1233+
// Ignore video command lists ('ID3D12VideoProcessCommandList', 'ID3D12VideoProcessCommandList', ...) in case they are created with the base 'ID3D12CommandList' interface
1234+
if (type >= D3D12_COMMAND_LIST_TYPE_DIRECT && type <= D3D12_COMMAND_LIST_TYPE_COPY)
12331235
{
1234-
*ppCommandList = command_list_proxy;
1236+
const auto command_list_proxy = new D3D12GraphicsCommandList(this, static_cast<ID3D12GraphicsCommandList *>(*ppCommandList));
1237+
1238+
// Upgrade to the actual interface version requested here (and only hook graphics command lists)
1239+
if (command_list_proxy->check_and_upgrade_interface(riid))
1240+
{
1241+
*ppCommandList = command_list_proxy;
12351242

12361243
#if RESHADE_ADDON
1237-
reshade::invoke_addon_event<reshade::addon_event::reset_command_list>(command_list_proxy);
1244+
reshade::invoke_addon_event<reshade::addon_event::reset_command_list>(command_list_proxy);
12381245
#endif
1239-
}
1240-
else // Do not hook object if we do not support the requested interface or this is a compute command list
1241-
{
1242-
reshade::log::message(reshade::log::level::warning, "Unknown interface %s in ID3D12Device4::CreateCommandList1.", reshade::log::iid_to_string(riid).c_str());
1246+
}
1247+
else // Do not hook object if we do not support the requested interface or this is a compute command list
1248+
{
1249+
reshade::log::message(reshade::log::level::warning, "Unknown interface %s in ID3D12Device4::CreateCommandList1.", reshade::log::iid_to_string(riid).c_str());
12431250

1244-
delete command_list_proxy; // Delete instead of release to keep reference count untouched
1251+
delete command_list_proxy; // Delete instead of release to keep reference count untouched
1252+
}
12451253
}
12461254
}
12471255
#if RESHADE_VERBOSE_LOG

source/d3d12/d3d12_device.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct DECLSPEC_UUID("2523AFF4-978B-4939-BA16-8EE876A4CB2A") D3D12Device final :
7878
HRESULT STDMETHODCALLTYPE EnqueueMakeResident(D3D12_RESIDENCY_FLAGS Flags, UINT NumObjects, ID3D12Pageable *const *ppObjects, ID3D12Fence *pFenceToSignal, UINT64 FenceValueToSignal) override;
7979
#pragma endregion
8080
#pragma region ID3D12Device4
81-
HRESULT STDMETHODCALLTYPE CreateCommandList1(UINT NodeMask, D3D12_COMMAND_LIST_TYPE Type, D3D12_COMMAND_LIST_FLAGS Flags, REFIID riid, void **ppCommandList) override;
81+
HRESULT STDMETHODCALLTYPE CreateCommandList1(UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, D3D12_COMMAND_LIST_FLAGS flags, REFIID riid, void **ppCommandList) override;
8282
HRESULT STDMETHODCALLTYPE CreateProtectedResourceSession(const D3D12_PROTECTED_RESOURCE_SESSION_DESC *pDesc, REFIID riid, void **ppSession) override;
8383
HRESULT STDMETHODCALLTYPE CreateCommittedResource1(const D3D12_HEAP_PROPERTIES *pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC *pDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE *pOptimizedClearValue, ID3D12ProtectedResourceSession *pProtectedSession, REFIID riidResource, void **ppvResource) override;
8484
HRESULT STDMETHODCALLTYPE CreateHeap1(const D3D12_HEAP_DESC *pDesc, ID3D12ProtectedResourceSession *pProtectedSession, REFIID riid, void **ppvHeap) override;

0 commit comments

Comments
 (0)