In Progress General GAME CRASH if banner color IDs are not continuous from 194

Users who are viewing this thread

Version number
1.2.1
Branch
Beta
Modded/unmodded
Modded
Summary:

When a mod uses custom color IDs not starting from 194, the game will crash when loading a saved game or creating a kingdom.

How to Reproduce:
  • Create a mod
  • In the file ModuleData/banner_icons.xml, add some colors with IDs not starting from 194, for example:
    XML:
    <?xml version="1.0" encoding="utf-8"?><base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <BannerIconData>
        <BannerColors>
          <Color id="520" hex="0xff000000" player_can_choose_for_sigil="true" player_can_choose_for_background="true" />
          <Color id="521" hex="0xffFFFFFF" player_can_choose_for_sigil="true" player_can_choose_for_background="true" />
          <Color id="522" hex="0xffFEDB97" player_can_choose_for_sigil="true" player_can_choose_for_background="true" />
          <Color id="523" hex="0xff4D85C0" player_can_choose_for_sigil="true" player_can_choose_for_background="true" />
        </BannerColors>
      </BannerIconData>
     </base>
  • Start a new sandbox game and design the banner using a new color
  • Save and load the game - it'll crash.
Specific Tool: No

I mentioned this bug before in this thread, but it seems to be ignored. So I'm reporting this again.

The method BannerManager.GetColorId seems not to be correctly implemented. It traverses the BannerManager.ColorPalette dictionary with indices from 0 to Count - 1. But since it's essentially a dictionary, the keys may not be continuous numbers.

This problem makes having multiple mods for expanding the color palette nearly impossible.

For now, I have to patch BannerManager.GetColorId using Harmony:

C#:
static bool Prefix(ref int __result, uint color)
{
    foreach (KeyValuePair<int, BannerColor> colorEntry in BannerManager.ColorPalette)
    {
        if (colorEntry.Value.Color == color)
        {
            __result = colorEntry.Key;
            break;
        }
    }
    __result = -1;
    return false;
}
 
Back
Top Bottom