Skip to content

Commit

Permalink
Fixed|libdoomsday: Incorrectly initialized color palette IDs
Browse files Browse the repository at this point in the history
Due to a refactoring oversight, the type of color palette IDs was
apparently changed to a plain uint32 from de::Id, and thus the IDs
were not being initialized at all.

Fixes a fatal error during game load.
  • Loading branch information
skyjake committed Jul 13, 2016
1 parent f478327 commit e48f4b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
Expand Up @@ -71,8 +71,6 @@ class LIBDOOMSDAY_PUBLIC ColorPalette
/// Notified whenever the color table changes.
DENG2_DEFINE_AUDIENCE(ColorTableChange, void colorPaletteColorTableChanged(ColorPalette &colorPalette))

typedef de::duint Id;

/// Palette index translation mapping table.
typedef QVector<int> Translation;

Expand Down
Expand Up @@ -42,7 +42,7 @@ class LIBDOOMSDAY_PUBLIC ColorPalettes
/**
* Returns the ColorPalette associated with unique @a id.
*/
ColorPalette &colorPalette(ColorPalette::Id id) const;
ColorPalette &colorPalette(de::Id const &id) const;

/**
* Returns the symbolic name of the specified color @a palette. A zero-length
Expand Down Expand Up @@ -72,7 +72,7 @@ class LIBDOOMSDAY_PUBLIC ColorPalettes
/**
* Returns the unique identifier of the current default color palette.
*/
ColorPalette::Id defaultColorPalette() const;
de::Id defaultColorPalette() const;

/**
* Change the default color palette.
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/libdoomsday/src/resource/colorpalette.cpp
Expand Up @@ -329,7 +329,7 @@ ColorPalette::Translation const *ColorPalette::translation(String id) const
return d->translation(id);
}

void ColorPalette::newTranslation(String id, Translation const &mappings)
void ColorPalette::newTranslation(String xlatId, Translation const &mappings)
{
LOG_AS("ColorPalette");

Expand All @@ -341,13 +341,13 @@ void ColorPalette::newTranslation(String id, Translation const &mappings)

DENG2_ASSERT(mappings.count() == colorCount()); // sanity check

if (!id.isEmpty())
if (!xlatId.isEmpty())
{
Translation *xlat = d->translation(id);
Translation *xlat = d->translation(xlatId);
if (!xlat)
{
// An entirely new translation.
xlat = &d->translations.insert(id, Translation()).value();
xlat = &d->translations.insert(xlatId, Translation()).value();
}

// Replace the whole mapping table.
Expand Down
19 changes: 7 additions & 12 deletions doomsday/apps/libdoomsday/src/resource/colorpalettes.cpp
Expand Up @@ -28,13 +28,13 @@ namespace res {

DENG2_PIMPL_NOREF(ColorPalettes)
{
typedef QMap<ColorPalette::Id, ColorPalette *> ColorPalettes;
typedef QMap<Id::Type, ColorPalette *> ColorPalettes;
ColorPalettes colorPalettes; // owned

typedef QMap<String, ColorPalette *> ColorPaletteNames;
ColorPaletteNames colorPaletteNames;

ColorPalette::Id defaultColorPalette = 0;
Id defaultColorPalette { Id::None };

~Impl()
{
Expand Down Expand Up @@ -65,18 +65,13 @@ dint ColorPalettes::colorPaletteCount() const
return d->colorPalettes.count();
}

ColorPalette &ColorPalettes::colorPalette(ColorPalette::Id id) const
ColorPalette &ColorPalettes::colorPalette(Id const &id) const
{
// Choose the default palette?
if(!id)
{
id = d->defaultColorPalette;
}

auto found = d->colorPalettes.find(id);
auto found = d->colorPalettes.find(id.isNone()? d->defaultColorPalette : id);
if(found != d->colorPalettes.end()) return *found.value();
/// @throw MissingResourceError An unknown/invalid id was specified.
throw Resources::MissingResourceError("ColorPalettes::colorPalette", "Invalid id " + String::number(id));
throw Resources::MissingResourceError("ColorPalettes::colorPalette",
"Invalid ID " + id.asText());
}

String ColorPalettes::colorPaletteName(ColorPalette &palette) const
Expand Down Expand Up @@ -122,7 +117,7 @@ void ColorPalettes::addColorPalette(res::ColorPalette &newPalette, String const
}
}

ColorPalette::Id ColorPalettes::defaultColorPalette() const
Id ColorPalettes::defaultColorPalette() const
{
return d->defaultColorPalette;
}
Expand Down

0 comments on commit e48f4b3

Please sign in to comment.