1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Game-Crashing Bug: City names with % in the event log

Discussion in 'Civ4 - Bug Reports' started by Lord Parkin, Mar 4, 2012.

  1. Lord Parkin

    Lord Parkin aka emperor

    Joined:
    Apr 27, 2004
    Messages:
    6,373
    Location:
    New Zealand
    It seems that weird and/or catastrophic things can happen when the % character is used in a city name. Specifically, the issue seems to occur when the city name is written to the event log – e.g. finishing an item in a build queue, or notifying of a nearby enemy. When the following combinations occur anywhere inside a city name which is posted to the event log, here is what happens:

    % c – will clear the rest of the city name
    % d – will replace with a number around -1 billion
    % e – will replace with a number around -1*10^-290
    % f – will replace with 0.000000
    % g – will replace with a number around -1*10^-290
    % i – will replace with a number around -1 billion
    % n – will immediately crash the game
    % o – will replace with a number around 27.7 billion
    % p – will replace with BF800000
    % s – will immediately crash the game
    % u – will replace with a number around 3.2 billion
    % x – will replace with bf800000

    I’m not a programmer so I’m not sure of what specifically is going on here, but one thing is clear: a % character in the city name causes complete havoc. It probably should have simply been disallowed as a character choice many years ago during bug testing, but apparently it was obscure enough that no-one ever noticed it. For the record, it happens in single player games as well as multiplayer games – whenever a city name which contains one of these combinations is posted to the event log, the result is madness.

    To see the bug in action: download the save attached below, load it up in Hotseat, change the city name to one of the combinations above (or leave it as is), press Enter to end turn twice, and watch the ensuing insanity. :)
     

    Attached Files:

  2. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,564
    Location:
    Australia
    I just tested and confirmed the bug.

    I assume that the bug is due to the city name being fed directly into a 'formatted string' function, like sprintf. It's a silly programming mistake for a professional to make...

    In the formatted string, the percentage sign signals that there a variable should be inserted at that point in the text. %c represents a single character, %d represents a decimal number, and so on. The problem is, no data has been prepared to fill those place-holders; and so unpredictable things can happen.

    Anyway, thanks for posting it. I'm going to see if I can fix the bug in K-Mod.
     
  3. karadoc

    karadoc AI programmer

    Joined:
    Oct 3, 2005
    Messages:
    1,564
    Location:
    Australia
    OK.. I've looked into this a bit, and as far as I can tell the fatal substitution of the % things is not fixable. ie. it happens somewhere in the .exe part of the game, for which we don't have the source code. However it is possible to strip the % characters out of the city names. I mean, I can't make it so that the % works correctly, but I can make it so that % is simply disallowed.

    While testing this, I noticed some other related behaviour.. You can type the name of text-keys from the game and they will be substituted in as your city's name. For example, if you rename your city to "TXT_KEY_WB_EXIT", your city will be called "Exit World Builder" - in the language set in the game options. -- Most of the text key names are too long to be allowed as city names, so there isn't much fun to be had here...

    One thing that is kind of fun though is that if you are renaming units, special keywords are substituted into their corresponding symbols. For example, if you name your unit "[ICON_CULTURE]", then it will be called :culture:. So you can get legitimate game messages that say things like "Your :strength: has destroyed a warrior!"
     
  4. Lord Parkin

    Lord Parkin aka emperor

    Joined:
    Apr 27, 2004
    Messages:
    6,373
    Location:
    New Zealand
    Interesting stuff, thanks for the input. I like the idea of making unit names appear as icons, that seems cool. Will have to give that one a try. :)
     
  5. r_rolo1

    r_rolo1 King of myself

    Joined:
    May 19, 2006
    Messages:
    13,818
    Location:
    Lisbon, Portugal
    :wallbash:

    That is simply sloppy coding :/ There is no way that a user input should be able to wreck havoc like that in a multi-level aplication like Civ IV is :(

    Hopefully the damage ends there ...
     
  6. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,768
    Location:
    an Aussie in Boston
    ahh - get over it. It happens :D. But look at the fun that can be had. I am totally trying this out.
     
  7. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,768
    Location:
    an Aussie in Boston
    That works for units but not for city names :(.
     

Share This Page