Skip to content

Commit

Permalink
Fixed|UI|Home: Random crash after editing package profiles
Browse files Browse the repository at this point in the history
Opening a PackagesDialog would refresh all packages, which would
result in a game readiness update notification, which in turn would
clear the game column’s contents, leading to a crash because the user
was in the process of editing a game profile.

Now game columns do not clear their contents when an update is needed,
but instead add, remove, or update individual items.
  • Loading branch information
skyjake committed Mar 18, 2017
1 parent 22dd59f commit d05cc8b
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions doomsday/apps/client/src/ui/home/gamecolumnwidget.cpp
Expand Up @@ -148,20 +148,19 @@ DENG_GUI_PIMPL(GameColumnWidget)
Config::get("home.showUnplayableGames").audienceForChange() += this;
}

ui::Item const *findProfileItem(GameProfile const &profile) const
ui::Item *findProfileItem(GameProfile const &profile) const
{
for (dsize i = 0; i < menu->items().size(); ++i)
{
ui::Item const &item = menu->items().at(i);
//qDebug() << i << item.label();
ui::Item &item = menu->items().at(i);
if (!item.semantics().testFlag(ui::Item::Separator))
{
if (item.as<ProfileItem>().profile == &profile) return &item;
}
}
return nullptr;
}

GamePanelButtonWidget &widgetForItem(ui::Item const &item) const
{
DENG2_ASSERT(menu->items().find(item) != ui::Data::InvalidPos);
Expand Down Expand Up @@ -244,12 +243,44 @@ DENG_GUI_PIMPL(GameColumnWidget)
*/
void populateItems()
{
menu->items().clear();
DoomsdayApp::gameProfiles().forAll([this] (GameProfile &profile)
QSet<GameProfile *> profiles;
foreach (GameProfile *prof,
DoomsdayApp::gameProfiles().profilesInFamily(gameFamily))
{
addItemForProfile(profile);
return LoopContinue;
});
profiles.insert(prof);
}
QSet<GameProfile *> toAdd = profiles;

// Update or remove profiles as needed.
for (ui::DataPos i = 0; i < menu->items().size(); ++i)
{
ui::Item const &item = menu->items().at(i);
if (item.semantics() & ui::Item::Separator)
{
// Skip the subheading.
continue;
}
auto const &profItem = item.as<ProfileItem>();
if (profiles.contains(profItem.profile))
{
// Already existing item.
toAdd.remove(profItem.profile);
profItem.update();
}
else
{
// Deleted profile.
menu->items().remove(i--);
}
}

// Add new items.
foreach (GameProfile *newProf, toAdd)
{
addItemForProfile(*newProf);
}

addOrRemoveSubheading();
sortItems();
}

Expand Down Expand Up @@ -562,7 +593,7 @@ GameColumnWidget::GameColumnWidget(String const &gameFamily,
}
}

d->populateItems();
//d->populateItems();
}

String GameColumnWidget::tabHeading() const
Expand Down

0 comments on commit d05cc8b

Please sign in to comment.