I recently upgraded my application from Delphi 2007 to Delphi XE8. In couple of forms, Form.showmodel line throws "Floating point division by zero" exception. On those forms there is No arithmetic operations done at all.
I tried executing following code before showmodal which resolved the issue.
var
CW, SW: word;
function GetX87CW: word;
ASM
FStCW [Result]
End;
Function GetX87SW: word; // Assembler;
ASM
FStSW [Result]
End;
CW := GetX87CW; SW := GetX87SW;
ShowMessage(Format('CW = $%4x, SW = $%4x',[CW,SW]));
I haven't saved this code and commented out all code and again recompiled the application which also resolved the issue.
Now I closed Delphi and restarted the XE8 IDE. I opened the project and this issue started appearing again but this time, even though I wrote the above code, it still is throwing exception.
Have any one seen such issue and can someone throw some light on possible cause of such issue ?
Are you using COM objects, e.g. calling .Net assemblies? Or OpenGL? Or some OleDB/ADO providers? Any other external .dll? I guess so.
Sounds like this issue. You should try to make external non Delphi call safe, by saving and restoring the FPU exception flags, for each call.
As Ken wrote:
var
Saved8087CW: Word;
begin
Saved8087CW := Default8087CW;
// If you want, disable all fpu exceptions
// with the next line.
Set8087CW($133F);
DoYourComOperationHere;
Set8087CW(Saved8087CW);
end;