Skip to content

Commit

Permalink
Fix crash on trying to get new patches info
Browse files Browse the repository at this point in the history
Passing a local variable with fastdelegate to another thread is not a good idea.
  • Loading branch information
FreeZoneMods committed Dec 14, 2018
1 parent 66945b9 commit 005a0de
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,22 +1682,33 @@ class CCC_DumpObjects : public IConsole_Command

class CCC_GSCheckForUpdates : public IConsole_Command
{
private:
CGameSpy_Patching::PatchCheckCallback m_resultCallbackBinded;
std::atomic<bool> m_checkInProgress = false;

void xr_stdcall ResultCallback(bool success, pcstr VersionName, pcstr URL)
{
auto mm = MainMenu();
if (mm != nullptr)
{
mm->OnPatchCheck(success, VersionName, URL);
}
m_checkInProgress.store(false);
}

public:
CCC_GSCheckForUpdates(LPCSTR N) : IConsole_Command(N) { bEmptyArgsHandled = true; };
CCC_GSCheckForUpdates(LPCSTR N) : IConsole_Command(N)
{
m_resultCallbackBinded.bind(this, &CCC_GSCheckForUpdates::ResultCallback);
bEmptyArgsHandled = true;
};

virtual void Execute(LPCSTR arguments)
{
if (!MainMenu())
auto mm = MainMenu();
if (mm == nullptr)
return;
/*
CGameSpy_Available GSA;
shared_str result_string;
if (!GSA.CheckAvailableServices(result_string))
{
Msg(*result_string);
// return;
};
CGameSpy_Patching GameSpyPatching;
*/

bool InformOfNoPatch = true;
if (arguments && *arguments)
{
Expand All @@ -1706,10 +1717,10 @@ class CCC_GSCheckForUpdates : public IConsole_Command
InformOfNoPatch = (bInfo != 0);
}
#ifdef WINDOWS
// GameSpyPatching.CheckForPatch(InformOfNoPatch);
CGameSpy_Patching::PatchCheckCallback cb;
cb.bind(MainMenu(), &CMainMenu::OnPatchCheck);
MainMenu()->GetGS()->GetGameSpyPatching()->CheckForPatch(InformOfNoPatch, cb);
if (!m_checkInProgress.exchange(true))
{
mm->GetGS()->GetGameSpyPatching()->CheckForPatch(InformOfNoPatch, m_resultCallbackBinded);
}
#endif
}
};
Expand Down

0 comments on commit 005a0de

Please sign in to comment.