Friday, 6/24/2011 11:46 AM
by Peter Kuhn
If you are interested in Silverlight 5 and its new 3D graphics capabilities, you probably know about the available samples on MSDN. One of them is the Housebuilder sample John Papa first presented during MIX11. For quite some time I've been struggling with this particular sample, because all I got when I tried to run it on various computers was this:
At first I thought it was a bug with Silverlight 5 (it is a beta version after all), but the setups of the computers that showed the problem were so different in both hardware and software that is seemed unlikely. Another computer that was almost identical to one that showed the bug ran the sample without problems. What was the problem?
It really took me a while to figure out what the problem is, but last night I finally found it: it hasn't anything to do with Silverlight 5's rendering capabilities at all. The assets of that particular sample are stored in an Xml format that has all the meshes with their geometry, UV sets and colors etc. as text. When that data is loaded, it is parsed back into the required native types like floats and doubles. The faux pas in the sample is that for this, the current culture is used.
coordinates.Add(new FloatUVValue(float.Parse(u), float.Parse(v)));
The machines that failed to render the samples had a different culture settings than en-US (in particular, they were set to de-DE). A string like "-0.5" is correctly parsed as -0.5 if the culture used during the parsing is en-US or the invariant culture. For some European cultures however, the decimal separators are different from the ones in the US, and then a string like "-0.5" is parsed as -5(!). This caused the above problems; the final result had nothing to do with the original data anymore.
You can simply switch your local culture settings (e.g. to en-US) to fix this, but I've also fixed the source code by changing the parsing of floats and doubles so it correctly takes the source format in the asset files into consideration. Since there are quite some places where this needs to be changed, I won't guide you through all the places. Instead I'm offering an archive with the fixed files for download here. So if you're having the same problems, do the following:
- Download and extract the original sample.
and extract it in the same location. Make sure you preserve the folder structure when you do this. You should be asked if you want to overwrite the existing files, which you need to confirm.
- Build and run the sample; it should now work regardless of the system's culture setting.
Have fun :)