r5sdk/r5dev/engine/host_cmd.cpp
Kawe Mazidjatari 165d80c541 Fix rare ImGui crash on shutdown
The 'DirectX_Init()' call was performed late in code, shortly after the window has been created (at this point all device objects and window handles are valid), but the 'DirectX_Shutdown()' call was performed on DLL_DETACH, which was way too late, as the objects were already destroyed at this point. This wasn't an issue before, as we created our own objects in the old DX code. But due to optimizations, we were using the same pointers as the game (noticeable performance boost), but did not adjust the shutdown to accommodate the changes. The shutdown is now performed while the device objects and window handles are valid. Code has been tested on Nvidia and AMD systems, and has confirmed to fix the aforementioned issues.
2023-06-18 22:16:43 +02:00

103 lines
2.7 KiB
C++

#include "core/stdafx.h"
#include "tier0/commandline.h"
#include "host_cmd.h"
#include "common.h"
#include "client/client.h"
#ifndef DEDICATED
#include "windows/id3dx.h"
#endif // !DEDICATED
/*
==================
Host_Shutdown
shutdown host
systems
==================
*/
void Host_Shutdown()
{
#ifndef DEDICATED
DirectX_Shutdown();
#endif // DEDICATED
v_Host_Shutdown();
}
/*
==================
Host_Status_PrintClient
Print client info
to console
==================
*/
void Host_Status_PrintClient(CClient* client, bool bShowAddress, void (*print) (const char* fmt, ...))
{
CNetChan* nci = client->GetNetChan();
const char* state = "challenging";
if (client->IsActive())
state = "active";
else if (client->IsSpawned())
state = "spawning";
else if (client->IsConnected())
state = "connecting";
if (nci != NULL)
{
print("# %i \"%s\" %llu %s %i %i %s %d\n",
client->GetHandle(), client->GetServerName(), client->GetNucleusID(), COM_FormatSeconds(static_cast<int>(nci->GetTimeConnected())),
static_cast<int>(1000.0f * nci->GetAvgLatency(FLOW_OUTGOING)), static_cast<int>(100.0f * nci->GetAvgLoss(FLOW_INCOMING)), state, nci->GetDataRate());
if (bShowAddress)
{
print(" %s\n", nci->GetAddress());
}
}
else
{
print("#%2i \"%s\" %llu %s\n", client->GetHandle(), client->GetServerName(), client->GetNucleusID(), state);
}
//print("\n");
}
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2)
/*
==================
DFS_InitializeFeatureFlagDefinitions
Initialize feature
flag definitions
==================
*/
bool DFS_InitializeFeatureFlagDefinitions(const char* pszFeatureFlags)
{
if (CommandLine()->CheckParm("-nodfs"))
return false;
return v_DFS_InitializeFeatureFlagDefinitions(pszFeatureFlags);
}
#endif // !(GAMEDLL_S0) || !(GAMEDLL_S1) || !(GAMEDLL_S2)
///////////////////////////////////////////////////////////////////////////////
void VHostCmd::Attach() const
{
DetourAttach(&v_Host_Shutdown, &Host_Shutdown);
DetourAttach(&v_Host_Status_PrintClient, &Host_Status_PrintClient);
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2)
DetourAttach(&v_DFS_InitializeFeatureFlagDefinitions, &DFS_InitializeFeatureFlagDefinitions);
#endif // !(GAMEDLL_S0) || !(GAMEDLL_S1) || !(GAMEDLL_S2)
}
void VHostCmd::Detach() const
{
DetourDetach(&v_Host_Shutdown, &Host_Shutdown);
DetourDetach(&v_Host_Status_PrintClient, &Host_Status_PrintClient);
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2)
DetourDetach(&v_DFS_InitializeFeatureFlagDefinitions, &DFS_InitializeFeatureFlagDefinitions);
#endif // !(GAMEDLL_S0) || !(GAMEDLL_S1) || !(GAMEDLL_S2)
}
///////////////////////////////////////////////////////////////////////////////
EngineParms_t* g_pEngineParms = nullptr;