Fix #1605: crash when downloading friends and achievements at the same time.

This commit is contained in:
hiker
2014-10-08 08:00:58 +11:00
parent 8818892bd2
commit d5bc5ec110
4 changed files with 27 additions and 14 deletions

View File

@@ -60,7 +60,7 @@ OnlineProfile::OnlineProfile(const uint32_t & userid,
const irr::core::stringw & username,
bool is_current_user)
{
m_state = S_READY;
m_state = (State)0;
m_cache_bit = true;
m_id = userid;
m_is_current_user = is_current_user;
@@ -112,7 +112,7 @@ OnlineProfile::OnlineProfile(const XMLNode * xml, ConstructorType type)
xml->get("id", &m_id );
xml->get("user_name", &m_username);
m_is_current_user = (m_id == PlayerManager::getCurrentOnlineId());
m_state = S_READY;
m_state = (State)0;
} // OnlineProfile(XMLNode)
// ----------------------------------------------------------------------------
@@ -132,7 +132,7 @@ void OnlineProfile::fetchAchievements()
if (m_has_fetched_achievements || m_is_current_user)
return;
m_state = S_FETCHING;
m_state = State(m_state | S_FETCHING_ACHIEVEMENTS);
// ------------------------------------------------------------------------
/** A simple class that receives the achievements, and calls the right
@@ -173,7 +173,7 @@ void OnlineProfile::storeAchievements(const XMLNode * input)
m_achievements = StringUtils::splitToUInt(achieved_string, ' ');
}
m_has_fetched_achievements = true;
m_state = S_READY;
m_state = State(m_state & ~S_FETCHING_ACHIEVEMENTS);
} // storeAchievements
// ----------------------------------------------------------------------------
@@ -187,7 +187,7 @@ void OnlineProfile::fetchFriends()
if (m_has_fetched_friends)
return;
m_state = S_FETCHING;
m_state = State(m_state | S_FETCHING_FRIENDS);
// ------------------------------------------------------------------------
class FriendsListRequest : public XMLRequest
@@ -239,7 +239,7 @@ void OnlineProfile::storeFriends(const XMLNode * input)
}
} // for i in nodes
m_has_fetched_friends = true;
m_state = S_READY;
m_state = State(m_state & ~S_FETCHING_FRIENDS);
} // storeFriends
// ----------------------------------------------------------------------------
@@ -296,7 +296,8 @@ void OnlineProfile::deleteRelationalInfo()
*/
const OnlineProfile::IDList& OnlineProfile::getFriends()
{
assert(m_has_fetched_friends && m_state == S_READY);
assert(m_has_fetched_friends &&
(m_state & S_FETCHING_FRIENDS) != 0);
return m_friends;
} // getFriends
@@ -305,7 +306,9 @@ const OnlineProfile::IDList& OnlineProfile::getFriends()
*/
const OnlineProfile::IDList& OnlineProfile::getAchievements()
{
assert(m_has_fetched_achievements && m_state == S_READY && !m_is_current_user);
assert(m_has_fetched_achievements &&
(m_state & S_FETCHING_ACHIEVEMENTS) == 0 &&
!m_is_current_user);
return m_achievements;
} // getAchievements

View File

@@ -78,8 +78,8 @@ private:
/** The profile can either be fetching data, or be ready. */
enum State
{
S_FETCHING = 1,
S_READY
S_FETCHING_ACHIEVEMENTS = 0x01,
S_FETCHING_FRIENDS = 0x02,
};
State m_state;
@@ -134,8 +134,18 @@ public:
bool hasFetchedFriends() const { return m_has_fetched_friends; }
// ------------------------------------------------------------------------
/** True if the profile is not fetching data atm. */
bool isReady() const { return m_state == S_READY; }
/** True if the profile has fetched friends. */
bool finishedFetchingFriends() const
{
return (m_state & S_FETCHING_FRIENDS) == 0;
} // finishedFetchingFriends
// ------------------------------------------------------------------------
/** True if the profile has fetched friends. */
bool finishedFetchingAchievements() const
{
return (m_state & S_FETCHING_ACHIEVEMENTS) == 0;
} // hasFetchedAchievements
// ------------------------------------------------------------------------
/** Returns true if this item is the current user. */

View File

@@ -157,7 +157,7 @@ void OnlineProfileAchievements::onUpdate(float delta)
{
if (!m_waiting_for_achievements) return;
if (!m_visiting_profile->isReady())
if (!m_visiting_profile->hasFetchedAchievements())
{
// This will display an increasing number of dots while waiting.
m_achievements_list_widget->renameItem("loading",

View File

@@ -164,7 +164,7 @@ void OnlineProfileFriends::onUpdate(float delta)
{
if(m_waiting_for_friends)
{
if(m_visiting_profile->isReady())
if(m_visiting_profile->hasFetchedFriends())
{
displayResults();
}