PDA

View Full Version : Windows Language Related Crashes



code_glitch
25-08-2011, 10:04 PM
Now, recently as many are aware I entered the Ludum Dare 21 and had some trouble.

Finally, the problem has been uncovered and I post this as a warning to future foreign developers...

IF YOU USE SYSUTILS OR STRTOFLOAT and similar procedures read carefully:

On continental translations such as French and I suspect German also, FLOATING POINT values in a string MUST have a , (COMMA) while on other translations it is a . (POINT).

Using the inappropriate decimal separator will result in various and seemingly random access violation, runtime errors and the like.

Sascha Willems: I remembered reading of this game (http://www.saschawillems.de/?page_id=89) and how it only ran on german versions of windows. This was in truth the link that must have snapped in my mind to test it on different languages of windows and it was a good choice too... I've spoken to a few other fellow Ludum Dare coders about this issue and they also report some odd behavior, however they used a try statement to avoid the fatal...

MS, why you did this I have no clue, for NT 7, change it back! please?

Not to take advantage of this, the source code for the above game would not be available would it as the problem may be solved ;D and I've always wanted to play that damn cool looking game :D

a very annoyed and semi-formal code_glitch that will in future install a fresh XP install for each new windows related task...

LP
26-08-2011, 06:42 AM
MS, why you did this I have no clue, for NT 7, change it back! please?

What Microsoft had to do with this?

In the beginning of your program, use this: DecimalSeparator:= '.'; // or ","

Also, properly written code shouldn't break because of this, if you use Try...Except statements for StrToFloat; StrToFloatDef will simply return default value if invalid character is found. Never seen access violations happen with these functions.

WILL
26-08-2011, 07:33 AM
What on earth is a "Windows Language"? It's like having the "Delphi" vs "Object Pascal" name argument... :P

Sascha Willems
26-08-2011, 07:57 AM
Well, as you hinted at I encountered those problems long time ago (I guess the first time a non-german user used one of my games).

But there is a simple solution : Replace the decimal separator yourself before storing and loading values. This is what I now do in all my apps/games and this is how I do it :

Saving values :
- Convert floating point value to string
- Replace the current decimal separator (stored in System.DecimalSeparator) with a '.' (always, no matter what language)
- Save to e.g. XML-Node

Loading values :
- Get string
- Replace all '.' with current decimal separator. So for e.g. german OS '.' will be replaced with ',', for all langauges using '.' nothing is changed
- Convert back to float

Another possibility would be to what LifePower mentioned, though I prefer the above one as I usually save/load to/from XML and it doesn't matter what value type you store to a node. And also this allows me to format my floats before saving them.

code_glitch
26-08-2011, 11:09 AM
Lifepower: If you query the NT kernel at the base of your XP and 7 installs and ask it to convert a string to a float, depending on the system language (in this case french) it returns the value it seems most appropriate for the langauge. I don't know if you knwo this but Microsoft makes a 'special' or rather custom built version of windows for french people to sell in france, german people for germany etc. Less so now with windows 7 and it being one installer where you choose the language, but many elements are similar to the garbage present on Windows 95 (I have a french install cd of that)... And that really only ran programs if they where french - and a LOT of stuff crashed.

And now you have seen code break because of this.

WILL: Windows language refers to the language the OS was aimed at, they make it easier to use by implementing umlauts and other grammatical symbols down to quite a low level - the . and , seperators being ported right down to NT level.

Sascha: I have to admit that that is quite a lot of work for just converting a string to float on different languages of an OS - I mean you'd expect those things to only tweak the UI not the actual way in which code runs!

I just started this thread because I know there are a lot of foreign languaged programmers here and just wanted them to know that sometimes languages do screw things up and as a reference so that no-one in the future goes through two days of garbage and have to install an XP VM in a different language just to try and debug a game...

farcodev
08-09-2011, 01:25 AM
i also uses if DecimalSeparator=','
then DecimalSeparator:='.';

And have no problem when the game is switched to french.