Tuesday, August 10, 2004

I installed XP SP2

So far, nothing broke. I had a pretty stable installation before this, and now, too. I've had two GPFs with zip folders (and didn't in XP SP1), but it seems to work. IE6 seems way better, but I really don't use it for navigation anymore, only for a bit of ASP.NET development (I only use Firefox for navigation, as I'm addicted to tabbed browsing, mouse gestures and adblock).
My software used some popups for drill-down in reports, and had those windows blocked. Exception lists are just two clicks aways, so, it won't be a problem.
The firewall asked me if RSS Bandit should be allowed to navigate, and while it seems to be the correct behavior, it didn't ask the same thing for AVG antivirus. Maybe it's something I didn't understand yet about it.

Thursday, August 05, 2004

A weird bug - This time I don't know where, but solved it

I'm deploying this Windows Forms application, which is actually a simple, but pretty text editor with some features like Intelissense and syntax highlighting. The application was tested on lots of environments and still, it managed to not work on any of the customer's computers. The culprit was the following innocent line:
MyFont = new Font("Courier New", 10);
Strange as it may seem, it was throwing the following exception:
************** Exception Text **************
System.TypeInitializationException: The type initializer
for "ICSharpCode.TextEditor.Document.FontContainer" threw an exception. --->
System.ArithmeticException: Overflow or underflow in the arithmetic operation.
at System.Drawing.Font.Initialize(FontFamily family, Single emSize,
FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font.Initialize(String familyName, Single emSize,
FontStyle style, GraphicsUnit unit)
at System.Drawing.Font..ctor(String familyName, Single emSize)

After a lot of Googling I found this KB article which mentions a similar problem and a possible solution. It was pretty close to the solution, but it didn't work. It seems to be some other software or driver interfering with my .NET application. I blame it on their anti-virus, as we tested it on lots of different hardware and software configurations (notebooks, desktops, developer machines) and none of them worked, but the same corporate anti-virus was present at all of these machines.
Since I cannot tell them to disable their anti-virus, lots and lots of desperate Googling (and the customer in need of the application), what I ended up doing was:
try
{
DefaultFont = new Font("Courier New", 10);
}
catch (ArithmeticException)
{
ResetFPU();
DefaultFont = new Font("Courier New", 10);
}

where ResetFPU stands for:
[DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int _controlfp(int n, int mask);

const int _RC_NEAR = 0x00000000;
const int _PC_53 = 0x00010000;
const int _EM_INVALID = 0x00000010;
const int _EM_UNDERFLOW = 0x00000002;
const int _EM_ZERODIVIDE = 0x00000008;
const int _EM_OVERFLOW = 0x00000004;
const int _EM_INEXACT = 0x00000001;
const int _EM_DENORMAL = 0x00080000;
const int _CW_DEFAULT = ( _RC_NEAR + _PC_53 +
_EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW +
_EM_INEXACT + _EM_DENORMAL);

static void ResetFPU()
{
_controlfp(_CW_DEFAULT ,0xfffff);
}


I hope this helps someone in the future...

This page is powered by Blogger. Isn't yours?