Ver código fonte

Fix race conditions

Clément Wolf 2 semanas atrás
pai
commit
a05d2daf94

+ 3 - 0
src/App/Osu/Bancho.cpp

@@ -223,6 +223,9 @@ void handle_packet(Packet *packet) {
             //      Online ones would be "Local scores", "Global", "Country", "Selected mods" etc
             //      While offline ones would be "By score", "By pp", etc
             bancho.osu->m_songBrowser2->onSortScoresChange(UString("Online Leaderboard"), 0);
+
+            // If server sent a score submission policy, update options menu to hide the checkbox
+            bancho.osu->m_optionsMenu->updateLayout();
         } else {
             convar->getConVarByName("mp_autologin")->setValue(false);
             bancho.osu->m_optionsMenu->logInButton->setText("Log in");

+ 0 - 2
src/App/Osu/BanchoNetworking.cpp

@@ -259,11 +259,9 @@ static void send_bancho_packet(CURL *curl, Packet outgoing) {
     if(hres == CURLHE_OK) {
         if(strstr(header->value, "submit=0") != NULL) {
             bancho.score_submission_policy = ServerPolicy::NO;
-            bancho.osu->m_optionsMenu->updateLayout();
             debugLog("Server doesn't want score submission. :(\n");
         } else if(strstr(header->value, "submit=1") != NULL) {
             bancho.score_submission_policy = ServerPolicy::YES;
-            bancho.osu->m_optionsMenu->updateLayout();
             debugLog("Server wants score submission! :D\n");
         }
 

+ 12 - 4
src/App/Osu/Database.cpp

@@ -391,8 +391,10 @@ void Database::update() {
                 addBeatmap(fullBeatmapPath);
             }
 
-            // update progress
-            m_fLoadingProgress = (float)m_iCurRawBeatmapLoadIndex / (float)m_iNumBeatmapsToLoad;
+            // update progress (another thread checks if progress >= 1.f to know when we're done)
+            float progress = (float)m_iCurRawBeatmapLoadIndex / (float)m_iNumBeatmapsToLoad;
+            if(progress >= 1.0f) progress = 0.99f;
+            m_fLoadingProgress = progress;
 
             // check if we are finished
             if(m_iCurRawBeatmapLoadIndex >= m_iNumBeatmapsToLoad ||
@@ -609,6 +611,10 @@ std::vector<UString> Database::getPlayerNamesWithScoresForUserSwitcher() {
 }
 
 Database::PlayerPPScores Database::getPlayerPPScores(UString playerName) {
+    PlayerPPScores ppScores;
+    ppScores.totalScore = 0;
+    if(getProgress() < 1.0f) return ppScores;
+
     std::vector<FinishedScore *> scores;
 
     // collect all scores with pp data
@@ -666,7 +672,6 @@ Database::PlayerPPScores Database::getPlayerPPScores(UString playerName) {
     // sort by pp
     std::sort(scores.begin(), scores.end(), ScoreSortComparator());
 
-    PlayerPPScores ppScores;
     ppScores.ppScores = std::move(scores);
     ppScores.totalScore = totalScore;
 
@@ -993,7 +998,10 @@ void Database::loadDB(Packet *db, bool &fallbackToRawLoad) {
 
         if(Osu::debug->getBool()) debugLog("Database: Reading beatmap %i/%i ...\n", (i + 1), m_iNumBeatmapsToLoad);
 
-        m_fLoadingProgress = ((float)(i + 1) / (float)m_iNumBeatmapsToLoad);
+        // update progress (another thread checks if progress >= 1.f to know when we're done)
+        float progress = (float)i / (float)m_iNumBeatmapsToLoad;
+        if(progress >= 1.f) progress = 0.99f;
+        m_fLoadingProgress = progress;
 
         if(m_iVersion < 20191107)  // see https://osu.ppy.sh/home/changelog/stable40/20191107.2
         {

+ 2 - 6
src/App/Osu/SongBrowser.cpp

@@ -709,7 +709,6 @@ void SongBrowser::draw(Graphics *g) {
             double highestSpeedStrain = 0.0;
             double highestStrain = 0.0;
             int highestStrainIndex = -1;
-            double averageStrain = 0.0;
             for(int i = 0; i < aimStrains.size(); i++) {
                 const double aimStrain = aimStrains[i];
                 const double speedStrain = speedStrains[i];
@@ -721,10 +720,7 @@ void SongBrowser::draw(Graphics *g) {
                 }
                 if(aimStrain > highestAimStrain) highestAimStrain = aimStrain;
                 if(speedStrain > highestSpeedStrain) highestSpeedStrain = speedStrain;
-
-                averageStrain += strain;
             }
-            averageStrain /= (double)aimStrains.size();
 
             // draw strain bar graph
             if(highestAimStrain > 0.0 && highestSpeedStrain > 0.0 && highestStrain > 0.0) {
@@ -2935,8 +2931,8 @@ CBaseUIButton *SongBrowser::addTopBarLeftButton(UString text) {
 }
 
 void SongBrowser::onDatabaseLoadingFinished() {
-    m_beatmaps = std::vector<DatabaseBeatmap *>(
-        m_db->getDatabaseBeatmaps());  // having a copy of the vector in here is actually completely unnecessary
+    // having a copy of the vector in here is actually completely unnecessary
+    m_beatmaps = std::vector<DatabaseBeatmap *>(m_db->getDatabaseBeatmaps());
 
     debugLog("SongBrowser::onDatabaseLoadingFinished() : %i beatmaps.\n", m_beatmaps.size());