@@ -19,19 +19,25 @@ DiscordSocial& DiscordSocial::instance(){
1919}
2020
2121void DiscordSocial::run (){
22- m_client = std::make_shared<Client>();
23- if (!m_client ){
22+ auto client = std::make_shared<Client>();
23+ if (!client ){
2424 log (" Failed to initialize DiscordSocialSDK." , " run()" , LoggingSeverity::Error);
25- m_client.reset ();
2625 return ;
2726 }
2827
29- m_client->SetApplicationId (m_app_id);
30- m_client->AddLogCallback ([&](auto message, auto severity){
31- log (message, " Internal" , severity);
32- }, m_log_level);
28+ m_client = std::move (client);
29+ try {
30+ m_client->SetApplicationId (m_app_id);
31+ m_client->AddLogCallback ([&](auto message, auto severity){
32+ log (message, " Internal" , severity);
33+ }, m_log_level);
3334
34- std::thread (&DiscordSocial::thread_loop, this ).detach ();
35+ m_thread = std::thread (&DiscordSocial::thread_loop, this );
36+ }catch (...){
37+ m_client.reset ();
38+ log (" Failed to start DiscordSocialSDK." , " run()" , LoggingSeverity::Error);
39+ throw ;
40+ }
3541}
3642
3743void DiscordSocial::thread_loop (){
@@ -59,9 +65,9 @@ void DiscordSocial::thread_loop(){
5965 }
6066 }
6167
62- log (" Discord Rich Presence update thread exiting..." , " thread_loop()" , LoggingSeverity::Info);
6368 m_running.store (false , std::memory_order_release);
6469 m_client.reset ();
70+ log (" Discord Rich Presence update thread exiting..." , " thread_loop()" , LoggingSeverity::Info);
6571}
6672
6773void DiscordSocial::update_rich_presence (){
@@ -111,8 +117,8 @@ void DiscordSocial::update_rich_presence(){
111117 }
112118 });
113119 }catch (const std::exception& e){
114- log (" Exception: " + std::string (e.what ()), " update_rp()" , LoggingSeverity::Error);
115120 m_running.store (false , std::memory_order_release);
121+ log (" Exception: " + std::string (e.what ()), " update_rp()" , LoggingSeverity::Error);
116122 }
117123}
118124
0 commit comments