From be8a8e9380add7210a7bfb20d1d989630319b4ce Mon Sep 17 00:00:00 2001 From: Mason Sciotti Date: Thu, 29 Mar 2018 14:33:46 -0700 Subject: [PATCH] ACTUALLY register the handlers on init --- src/discord_rpc.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/discord_rpc.cpp b/src/discord_rpc.cpp index 635bba7..3dd3a74 100644 --- a/src/discord_rpc.cpp +++ b/src/discord_rpc.cpp @@ -47,6 +47,7 @@ struct JoinRequest { }; static RpcConnection* Connection{nullptr}; +static DiscordEventHandlers QueuedHandlers{}; static DiscordEventHandlers Handlers{}; static std::atomic_bool WasJustConnected{false}; static std::atomic_bool WasJustDisconnected{false}; @@ -282,12 +283,16 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId, { std::lock_guard guard(HandlerMutex); + if (handlers) { - Handlers = *handlers; + QueuedHandlers = *handlers; } else { - Handlers = {}; + QueuedHandlers = {}; } + + Handlers = {}; + } if (Connection) { @@ -296,13 +301,17 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId, Connection = RpcConnection::Create(applicationId); Connection->onConnect = []() { - Discord_UpdateHandlers(&Handlers); + Discord_UpdateHandlers(&QueuedHandlers); WasJustConnected.exchange(true); ReconnectTimeMs.reset(); }; Connection->onDisconnect = [](int err, const char* message) { LastDisconnectErrorCode = err; StringCopy(LastDisconnectErrorMessage, message); + { + std::lock_guard guard(HandlerMutex); + Handlers = {}; + } WasJustDisconnected.exchange(true); UpdateReconnectTime(); };