Skip to content

Commit

Permalink
Disabled floating-point exception handling when ResizeTargets is call…
Browse files Browse the repository at this point in the history
…ed, because it causes all CryTek games to crash
  • Loading branch information
Kaldaien committed Dec 26, 2024
1 parent c2cd3bc commit bc9c355
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
==========
+ Fixed potential deadlock in RenoDX mods, the ones that do not check for
nullptr before dereferencing ptrs will simply have to crash until fixed.
+ Disabled floating-point exception handling when ResizeTargets is called,
because it causes all CryTek games to crash.

24.12.26
========
Expand Down
17 changes: 6 additions & 11 deletions src/render/dxgi/dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8451,11 +8451,11 @@ SK_HookDXGI (void)
{
SK_DXGI_DetermineHighestSupportedFactoryVersion ();

bool bEnable = SK_EnableApplyQueuedHooks ();
{
SK_ApplyQueuedHooks ();
}
if (! bEnable) SK_DisableApplyQueuedHooks ();
//bool bEnable = SK_EnableApplyQueuedHooks ();
//{
// SK_ApplyQueuedHooks ();
//}
//if (! bEnable) SK_DisableApplyQueuedHooks ();

static const IID iids [] = { IID_IDXGIFactory, IID_IDXGIFactory1, IID_IDXGIFactory2,
IID_IDXGIFactory3, IID_IDXGIFactory4, IID_IDXGIFactory5,
Expand All @@ -8480,9 +8480,6 @@ SK_HookDXGI (void)

else
{
auto suspended =
SK_SuspendAllOtherThreads ();

// Thus we need to use a secondary thread
HANDLE hSecondaryThread =
SK_Thread_CreateEx ([](LPVOID)->DWORD
Expand All @@ -8497,11 +8494,9 @@ SK_HookDXGI (void)
// because this could deadlock otherwise.
if (hSecondaryThread != 0)
{
WaitForSingleObject (hSecondaryThread, 100UL);
WaitForSingleObject (hSecondaryThread, 500UL);
SK_CloseHandle (hSecondaryThread);
}

SK_ResumeThreads (suspended);
}

initializing_dxgi = true;
Expand Down
4 changes: 4 additions & 0 deletions src/render/dxgi/dxgi_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,10 @@ SK_DXGI_SwapChain_ResizeTarget_Impl (
_In_ const DXGI_MODE_DESC *pNewTargetParameters,
BOOL bWrapped )
{
// Fix for CryTek's stupid engine enabling floating-point exceptions
_control87 (0x0, _MCW_EM);
_controlfp (0x0, _MCW_EM);

const auto
_Return =
[&](HRESULT hr)
Expand Down

0 comments on commit bc9c355

Please sign in to comment.