From 1a5644bd9b25ca4d6511e916104a3828110df2fa Mon Sep 17 00:00:00 2001 From: Cvolton Date: Mon, 16 Sep 2024 14:08:07 +0200 Subject: [PATCH] fix leaderboard loading exit crash --- src/layers/LeaderboardViewLayer.cpp | 4 ++++ src/layers/LeaderboardViewLayer.h | 2 ++ src/managers/BetterInfoOnline.cpp | 11 ++++++++++- src/managers/BetterInfoOnline.h | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/layers/LeaderboardViewLayer.cpp b/src/layers/LeaderboardViewLayer.cpp index e5fe2cf..128d17d 100644 --- a/src/layers/LeaderboardViewLayer.cpp +++ b/src/layers/LeaderboardViewLayer.cpp @@ -77,4 +77,8 @@ void LeaderboardViewLayer::onLeaderboardFinished(cocos2d::CCArray* scores) { setData(scores); loadPage(); hideCircle(); +} + +LeaderboardViewLayer::~LeaderboardViewLayer() { + BetterInfoOnline::sharedState()->cancelScoresRequest(this); } \ No newline at end of file diff --git a/src/layers/LeaderboardViewLayer.h b/src/layers/LeaderboardViewLayer.h index b0ffa21..afbe3db 100644 --- a/src/layers/LeaderboardViewLayer.h +++ b/src/layers/LeaderboardViewLayer.h @@ -15,4 +15,6 @@ class BI_DLL LeaderboardViewLayer : public BIViewLayer, public BILeaderboardDele static cocos2d::CCScene* scene(int accountID); void onLeaderboardFinished(cocos2d::CCArray* scores); + + ~LeaderboardViewLayer(); }; \ No newline at end of file diff --git a/src/managers/BetterInfoOnline.cpp b/src/managers/BetterInfoOnline.cpp index 7bd0a47..9c69393 100644 --- a/src/managers/BetterInfoOnline.cpp +++ b/src/managers/BetterInfoOnline.cpp @@ -26,6 +26,8 @@ void BetterInfoOnline::loadScores(int accountID, bool force, BILeaderboardDelega return; } + m_delegates.insert(delegate); + static std::unordered_map tasks; tasks.emplace(accountID, ServerUtils::getBaseRequest(false) .bodyString(fmt::format("{}&accountID={}&udid={}&type=relative&secret=Wmfd2893gb7", ServerUtils::getBasePostString(false), accountID, std::string(GameManager::sharedState()->m_playerUDID))) @@ -33,7 +35,10 @@ void BetterInfoOnline::loadScores(int accountID, bool force, BILeaderboardDelega .map([this, accountID, delegate, profilePage](web::WebResponse* response) { if(response->ok()) { generateScores(response->string().unwrapOr(""), accountID); - sendScores(m_scoreDict[accountID], accountID, delegate, profilePage); + if(m_delegates.contains(delegate)) { + sendScores(m_scoreDict[accountID], accountID, delegate, profilePage); + m_delegates.erase(delegate); + } BetterInfoCache::sharedState()->cacheScoresResult(m_scoreDict[accountID]); } @@ -129,3 +134,7 @@ void BetterInfoOnline::sendScoreToProfilePage(cocos2d::CCArray* scores, int acco } } } + +void BetterInfoOnline::cancelScoresRequest(BILeaderboardDelegate* delegate){ + m_delegates.erase(delegate); +} \ No newline at end of file diff --git a/src/managers/BetterInfoOnline.h b/src/managers/BetterInfoOnline.h index 59adce4..4b759bf 100644 --- a/src/managers/BetterInfoOnline.h +++ b/src/managers/BetterInfoOnline.h @@ -13,6 +13,7 @@ class BI_DLL BetterInfoOnline : public cocos2d::CCObject { public: std::map> m_scoreDict; + std::set m_delegates; bool init(); static BetterInfoOnline* sharedState(){ @@ -29,4 +30,5 @@ class BI_DLL BetterInfoOnline : public cocos2d::CCObject { void generateScores(const std::string& response, int accountID); void sendScores(cocos2d::CCArray* scores, int accountID, BILeaderboardDelegate* delegate, Ref profilePage); void sendScoreToProfilePage(cocos2d::CCArray* scores, int accountID, Ref profilePage); + void cancelScoresRequest(BILeaderboardDelegate* delegate); }; \ No newline at end of file