0

I am working with a .NET 3.5 application in C# that calls some legacy C++ code regularly. I've noticed that calling into the C++ sometimes leads to an "Overflow or underflow arithmetic operation" when I mouse over an Infragistics UltraGrid that has a dropdown list. I've discovered that this only happens when the C++ codes does the following:

Word SavedWord = Default8087CW;
Set8087CW(0x133f); // Disable all fpu exceptions

...

Set8087CW(SavedWord);

If I comment out the last line, I no longer get the error in my .NET application. I haven't noticed any other side effects in the rest of the application. As a quick fix, I would like to leave this line commented out. What are the consequences of disabling FPU exceptions and not resetting the control word?

Kromster
  • 7,181
  • 7
  • 63
  • 111
Everett
  • 1,077
  • 5
  • 23
  • 42
  • Is the value of Default8087CW what the real value was upon entry to your C++ function or is it what the C++ RTL thinks is the default? The two may differ. – 500 - Internal Server Error May 29 '12 at 18:18
  • @500-InternalServerError, how would I check that? All I've been able to confirm is that the value of Default8087CW upon exit of the C++ code is the same as it was upon entry. – Everett May 29 '12 at 18:25
  • I'm not familiar with how to do this in C++. Isn't there a corresponding Get8087CW() function? – 500 - Internal Server Error May 29 '12 at 18:33
  • From what I can tell Default8087CW is the equivalent of Get8087CW(). Get8087CW() doesn't actually exist in this version of C++. Reference: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_Default8087CW.html – Everett May 29 '12 at 18:49

2 Answers2

2

The solution is found here: "StackOverFlowException in WPF when call method from C++ library".

Thanks to Hans Passant for this.

Community
  • 1
  • 1
Everett
  • 1,077
  • 5
  • 23
  • 42
0

After testing on other machines, it appears that commenting out the Set8087CW(SavedWord); line only fixes the issue on my machine. There appears to be a bug in my version of Infragistics (8.2.20082.2204). Rolling back to 8.2.20082.1000 fixed the issue.

Everett
  • 1,077
  • 5
  • 23
  • 42
  • 1
    Hmm, doubtful. There's a *lot* of code that is not compatible with the changes that the Borland runtime makes to the FPU control word. *Any* .NET code will be vulnerable. You must have already run into some code like that, considering you already found this snippet in your program. Here's another example: http://stackoverflow.com/a/8357646/17034 – Hans Passant May 30 '12 at 17:32
  • That's a very interesting post, @HansPassant. I've switched back to the newer version of Infragistics and implemented the solution mentioned there. Seems to work. Do you want to add an answer with a reference to that post? – Everett May 30 '12 at 18:06