Skip to content

Commit

Permalink
fix leaderboard loading exit crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Sep 16, 2024
1 parent dc1324d commit 1a5644b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/layers/LeaderboardViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ void LeaderboardViewLayer::onLeaderboardFinished(cocos2d::CCArray* scores) {
setData(scores);
loadPage();
hideCircle();
}

LeaderboardViewLayer::~LeaderboardViewLayer() {
BetterInfoOnline::sharedState()->cancelScoresRequest(this);
}
2 changes: 2 additions & 0 deletions src/layers/LeaderboardViewLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ class BI_DLL LeaderboardViewLayer : public BIViewLayer, public BILeaderboardDele
static cocos2d::CCScene* scene(int accountID);

void onLeaderboardFinished(cocos2d::CCArray* scores);

~LeaderboardViewLayer();
};
11 changes: 10 additions & 1 deletion src/managers/BetterInfoOnline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ void BetterInfoOnline::loadScores(int accountID, bool force, BILeaderboardDelega
return;
}

m_delegates.insert(delegate);

static std::unordered_map<int, web::WebTask> 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)))
.post(fmt::format("{}/getGJScores20.php", ServerUtils::getBaseURL()))
.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]);
}

Expand Down Expand Up @@ -129,3 +134,7 @@ void BetterInfoOnline::sendScoreToProfilePage(cocos2d::CCArray* scores, int acco
}
}
}

void BetterInfoOnline::cancelScoresRequest(BILeaderboardDelegate* delegate){
m_delegates.erase(delegate);
}
2 changes: 2 additions & 0 deletions src/managers/BetterInfoOnline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BI_DLL BetterInfoOnline : public cocos2d::CCObject {

public:
std::map<int, Ref<cocos2d::CCArray>> m_scoreDict;
std::set<BILeaderboardDelegate*> m_delegates;

bool init();
static BetterInfoOnline* sharedState(){
Expand All @@ -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> profilePage);
void sendScoreToProfilePage(cocos2d::CCArray* scores, int accountID, Ref<ProfilePage> profilePage);
void cancelScoresRequest(BILeaderboardDelegate* delegate);
};

0 comments on commit 1a5644b

Please sign in to comment.