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

Lord Parkin

aka emperor
Joined
Apr 27, 2004
Messages
6,374
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. :)
 

Attachments

  • Crash Test.zip
    8.8 KB · Views: 46
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.
 
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!"
 
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. :)
 
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!"
: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 ...
 
ahh - get over it. It happens :D. But look at the fun that can be had. I am totally trying this out.
 
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!"
That works for units but not for city names :(.
 
Top Bottom