@@ -601,24 +601,28 @@ static void ApplyProfileSwitchRuntimeConfig(const Config& previousConfig) {
601601 }
602602
603603 SaveTheme ();
604+
604605 if (ImGui::GetCurrentContext () != nullptr ) {
605606 ApplyAppearanceConfig ();
606607 }
608+
607609 RequestDynamicGuiFontRefresh (true );
608610
609611 ApplyKeyRepeatSettings ();
612+
610613 if (g_config.confineCursor ) {
611614 ApplyConfineCursorToGameWindow ();
612615 } else {
613616 ClipCursorDirect (NULL );
614617 }
618+
615619 SetGlobalMirrorGammaMode (g_config.mirrorGammaMode );
616620
617621 const bool previousNinjabrainEnabled = previousConfig.ninjabrainOverlay .enabled ;
618622 const bool currentNinjabrainEnabled = g_config.ninjabrainOverlay .enabled ;
619623 if (!currentNinjabrainEnabled) {
620624 if (previousNinjabrainEnabled) {
621- StopNinjabrainClient ();
625+ StopNinjabrainClientAsync ();
622626 }
623627 return ;
624628 }
@@ -629,7 +633,7 @@ static void ApplyProfileSwitchRuntimeConfig(const Config& previousConfig) {
629633 }
630634
631635 if (previousConfig.ninjabrainOverlay .apiBaseUrl != g_config.ninjabrainOverlay .apiBaseUrl ) {
632- RestartNinjabrainClient ();
636+ RestartNinjabrainClientAsync ();
633637 }
634638}
635639
@@ -720,6 +724,7 @@ void SwitchProfile(const std::string& newProfileName) {
720724 std::string resolvedNewProfileName;
721725 bool failedToSavePreviousProfile = false ;
722726 bool failedToSaveProfilesMetadata = false ;
727+
723728 const bool pendingConfigSave = g_configIsDirty.load (std::memory_order_acquire);
724729
725730 {
@@ -770,14 +775,6 @@ void SwitchProfile(const std::string& newProfileName) {
770775
771776 RemoveInvalidHotkeyModeReferences (g_config);
772777 ResetAllHotkeySecondaryModes (g_config);
773- {
774- std::lock_guard<std::mutex> lock (g_modeIdMutex);
775- g_currentModeId = g_config.defaultMode ;
776- int nextIndex = 1 - g_currentModeIdIndex.load (std::memory_order_relaxed);
777- g_modeIdBuffers[nextIndex] = g_config.defaultMode ;
778- g_currentModeIdIndex.store (nextIndex, std::memory_order_release);
779- }
780- WriteCurrentModeToFile (g_config.defaultMode );
781778
782779 {
783780 std::lock_guard<std::mutex> lock (g_hotkeyMainKeysMutex);
@@ -792,7 +789,9 @@ void SwitchProfile(const std::string& newProfileName) {
792789 for (const auto & [id, inst] : g_userImages) {
793790 if (inst.isAnimated ) {
794791 for (GLuint tex : inst.frameTextures ) {
795- if (tex != 0 ) g_texturesToDelete.push_back (tex);
792+ if (tex != 0 ) {
793+ g_texturesToDelete.push_back (tex);
794+ }
796795 }
797796 } else if (inst.textureId != 0 ) {
798797 g_texturesToDelete.push_back (inst.textureId );
@@ -804,12 +803,21 @@ void SwitchProfile(const std::string& newProfileName) {
804803
805804 g_allImagesLoaded = false ;
806805 g_pendingImageLoad = true ;
806+
807807 RecalculateModeDimensions ();
808808 RequestScreenMetricsRecalculation ();
809- PublishConfigSnapshot ();
809+ PublishGuiConfigSnapshot ();
810810
811- ApplyProfileSwitchRuntimeConfig (previousConfig);
811+ {
812+ std::lock_guard<std::mutex> lock (g_modeIdMutex);
813+ g_currentModeId = g_config.defaultMode ;
814+ const int nextIndex = 1 - g_currentModeIdIndex.load (std::memory_order_relaxed);
815+ g_modeIdBuffers[nextIndex] = g_config.defaultMode ;
816+ g_currentModeIdIndex.store (nextIndex, std::memory_order_release);
817+ }
812818
819+ WriteCurrentModeToFile (g_config.defaultMode );
820+ ApplyProfileSwitchRuntimeConfig (previousConfig);
813821 g_configIsDirty.store (pendingConfigSave, std::memory_order_release);
814822}
815823
0 commit comments