Skip to content

Commit

Permalink
fix(common): cross-module recursive error support
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed Jan 6, 2021
1 parent 3741cf4 commit 913a444
Showing 1 changed file with 72 additions and 6 deletions.
78 changes: 72 additions & 6 deletions code/client/common/Error.cpp
Expand Up @@ -123,19 +123,85 @@ static int SysError(const char* buffer)
return 0;
}

struct ErrorDataPerProcess
{
bool inFatalError = false;
std::string lastFatalError;
};

struct ErrorData
{
ErrorDataPerProcess* perProcess;

bool inRecursiveError = false;
std::string lastRecursiveError;

bool inError = false;
std::string lastError;
};

#if defined(COMPILING_CORE) || defined(COMPILING_LAUNCHER)
extern "C" DLL_EXPORT ErrorData* GetErrorData()
{
static thread_local ErrorData errorData;
if (!errorData.perProcess)
{
static ErrorDataPerProcess edpp;
errorData.perProcess = &edpp;
}

return &errorData;
}
#elif defined(_WIN32)
inline ErrorData* GetErrorData()
{
using TCoreFunc = decltype(&GetErrorData);

static TCoreFunc func;

if (!func)
{
auto hCore = GetModuleHandleW(L"CoreRT.dll");

if (hCore)
{
func = (TCoreFunc)GetProcAddress(hCore, "GetErrorData");
}
}

return (func) ? func() : 0;
}
#else
extern "C" ErrorData* GetErrorData();
#endif

static int GlobalErrorHandler(int eType, const char* buffer)
{
static thread_local bool inError = false;
static thread_local std::string lastError;
static bool inFatalError = false;
static std::string lastFatalError;
auto errorData = GetErrorData();

if (!errorData)
{
static thread_local ErrorData dummyErrorData;
if (!dummyErrorData.perProcess)
{
static ErrorDataPerProcess edpp;
dummyErrorData.perProcess = &edpp;
}

errorData = &dummyErrorData;
}

bool& inError = errorData->inError;
std::string& lastError = errorData->lastError;
bool& inFatalError = errorData->perProcess->inFatalError;
std::string& lastFatalError = errorData->perProcess->lastFatalError;

trace("Error: %s\n", buffer);

if (inError || (eType == ERR_FATAL && inFatalError))
{
static thread_local bool inRecursiveError = false;
static thread_local std::string lastRecursiveError;
bool& inRecursiveError = errorData->inRecursiveError;
std::string& lastRecursiveError = errorData->lastRecursiveError;

if (inRecursiveError)
{
Expand Down

1 comment on commit 913a444

@Cockpitbuilders
Copy link

@Cockpitbuilders Cockpitbuilders commented on 913a444 Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this Update now crashes on FiveM Load with Wsupport64.dll which is a License Dongle for my multi projector setup from https://fly.elise-ng.net/ I need to rename my Wsupport64.dll file and then I can launch FiveM . Any way to have FiveM Ignore this DLL file as it has absolutely nothing to do with it? Thanks.

Before this update, I had no issues.

Please sign in to comment.