Skip to content

Commit

Permalink
UI|libdoomsday: Error loading game logos
Browse files Browse the repository at this point in the history
The background thread loading the logo was sometimes accessing the wrong catalog.
  • Loading branch information
skyjake committed Nov 26, 2018
1 parent 3a6b398 commit 6a38c1c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
3 changes: 2 additions & 1 deletion doomsday/apps/client/src/resource/idtech1image.cpp
Expand Up @@ -111,8 +111,9 @@ Image IdTech1Image::makeGameLogo(Game const &game,
{
if (flags & NullImageIfFails) return Image();

LOG_RES_WARNING("Failed to load title picture for game \"%s\": %s")
LOG_RES_WARNING("Failed to load title picture for game \"%s\" using {%s}: %s")
<< game.title()
<< String::join(catalog.packages(), " ")
<< er.asText();
}
if (flags & NullImageIfFails)
Expand Down
Expand Up @@ -184,7 +184,8 @@ void MultiplayerPanelButtonWidget::updateContent(shell::ServerInfo const &info)

if (d->catalog.setPackages(game.requiredPackages()))
{
*d += async([this, &game]() { return IdTech1Image::makeGameLogo(game, d->catalog); },
res::LumpCatalog catalog{d->catalog};
*d += async([&game, catalog]() { return IdTech1Image::makeGameLogo(game, catalog); },
[this](const Image &logo) { icon().setImage(logo); });
}
}
Expand Down
Expand Up @@ -36,6 +36,8 @@ class LIBDOOMSDAY_PUBLIC LumpCatalog
{
public:
LumpCatalog();

LumpCatalog(const LumpCatalog &);

void clear();

Expand All @@ -49,6 +51,8 @@ class LIBDOOMSDAY_PUBLIC LumpCatalog
* @return @c true, if the list of packages is different than the one set previously.
*/
bool setPackages(de::StringList packageIds);

de::StringList packages() const;

de::Block read(de::String const &lumpName) const;

Expand Down
38 changes: 31 additions & 7 deletions doomsday/apps/libdoomsday/src/resource/lumpcatalog.cpp
Expand Up @@ -34,9 +34,17 @@ DENG2_PIMPL(LumpCatalog)
using Found = std::pair<DataBundle const *, LumpDirectory::Pos>;

StringList packageIds;
QList<DataBundle const *> bundles; /// @todo Should observe for deletion. -jk

Impl(Public *i) : Base(i) {}
QList<const DataBundle *> bundles;

Impl(Public *i)
: Base(i)
{}

Impl(Public *i, const Impl &other)
: Base(i)
, packageIds(other.packageIds)
, bundles(other.bundles)
{}

void clear()
{
Expand Down Expand Up @@ -70,11 +78,18 @@ DENG2_PIMPL(LumpCatalog)
// The last bundle is checked first.
for (int i = bundles.size() - 1; i >= 0; --i)
{
auto const pos = bundles.at(i)->lumpDirectory()->find(lumpName);
if (pos != LumpDirectory::InvalidPos)
if (const auto *bundle = maybeAs<DataBundle>(bundles.at(i)))
{
auto const pos = bundle->lumpDirectory()->find(lumpName);
if (pos != LumpDirectory::InvalidPos)
{
found = Found(bundle, pos);
break;
}
}
else
{
found = Found(bundles.at(i), pos);
break;
qDebug() << "LumpCatalog is outdated: a bundle has been deleted";
}
}
return found;
Expand All @@ -84,6 +99,10 @@ DENG2_PIMPL(LumpCatalog)
LumpCatalog::LumpCatalog()
: d(new Impl(this))
{}

LumpCatalog::LumpCatalog(const LumpCatalog &other)
: d(new Impl(this, *other.d))
{}

void LumpCatalog::clear()
{
Expand All @@ -101,6 +120,11 @@ bool LumpCatalog::setPackages(StringList packageIds)
return false;
}

StringList LumpCatalog::packages() const
{
return d->packageIds;
}

Block LumpCatalog::read(String const &lumpName) const
{
Block data;
Expand Down

0 comments on commit 6a38c1c

Please sign in to comment.