Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-03

What's "External: SIGFPE"?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

Hi All,

I am making a charting program and encountered very weird error. The exception raised is: 'External: SIGFPE'. In file 'lcltype.pp' at line
3009. On that line is the MulDiv() function, and the operation I am doing is just assigning font height. I then remembered the question i asked days ago about 1/0 and Ln(0). Sven suggested to use SetExceptionMask.

I tried this in my FormCreate:

  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow,
exUnderflow]);

Now the program crashes every time it start. I also tested to put the above line on an empty project, same error happened in gtk2winapi.inc!

Could anyone explain what's SIGFPE? Why there is a SetExceptionMask? Why a normal empty form application will generate SIGFPE with these masks, and how to trace down to the cause of this error?

Thanks a lot!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130307/89a79bd2/attachment.html>

Reply by email

leledumbo
to Xiangrong Fang
Could anyone explain what's SIGFPE?

SIGFPE stands for SIGnal Floating Point Exception, that is caused by a probably invalid operation involving floating points.

Why there is a SetExceptionMask?

Probably to override the same thing already done by (implicitly used) libraries, e.g. gtk2

Why a normal empty form application will generate SIGFPE with these masks, and how to trace down to the cause of this error?

Because setting the mask means telling the processor to generate (or not to generate? I forgot) SIGFPE for the given operations. e.g. exZeroDivide may trigger SIGFPE if there's a division by zero with floating point operation. How to trace? You already get it, the program will report the line that causes it, you can directly go to the respective line to see what happens. But this requires that the code lies in the program space (not in external library) and the code is compiled with runtime error backtrace (-gl). Otherwise, the program can only report as deep as it can find.

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-What-s-External-SIGFPE-tp4029706p4029715.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Xiangrong Fang
to leledumbo

2013/3/7 leledumbo

Show quoted text 9 lines
Because setting the mask means telling the processor to generate (or not to generate? I forgot) SIGFPE for the given operations. e.g. exZeroDivide may trigger SIGFPE if there's a division by zero with floating point operation. How to trace? You already get it, the program will report the line that causes it, you can directly go to the respective line to see what happens. But this requires that the code lies in the program space (not in external library) and the code is compiled with runtime error backtrace (-gl). Otherwise, the program can only report as deep as it can find.

I don't understand:

1) even if I set the masks, why an empty LCL application generate SIGFPE? It means that somewhere GTK or whatever library *indeed* do things like 1/0, only that they are normally hidden/not reported?

2) I already found the problem in my code which is a like look like:

*if tbLog.Down then Y := exp(Y);*

And Y is a big number e.g. 2500, which caused floating point overflow. The problem was that the number itself should be Log()ed, so that exp() only restore its original value. That was my bug, but the weird thing is that SIGFPE is generated in unit LCLType on the line that set font height, which is very innocent, and after I commented out the font.Height operation, the SIGFPE slipped to somewhere else, but NEVER on the line that generated it!

Could you explain why? and how to locate where the SIGFPE occurred?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130307/444d86ff/attachment.html>

Reply by email

Kostas Michalopoulos
to Xiangrong Fang

Most likely it is your GTK+ theme. Many GTK+ themes and theme engines abuse floating point calculations which go unnoticed normally since the vast majority of C/C++ programs do not check for them. The solution is to do something like (IIRC):

SetExceptionMask([]);

Which disables all floating point exceptions. Alternatively switch to a theme that doesn't mess FP calculations, bu you can't guarantee that your users will have it.

Xiangrong Fang wrote 46 lines
2013/3/7 leledumbo > Because setting the mask means telling the processor to generate (or not > to > generate? I forgot) SIGFPE for the given operations. e.g. exZeroDivide may > trigger SIGFPE if there's a division by zero with floating point > operation. > How to trace? You already get it, the program will report the line that > causes it, you can directly go to the respective line to see what happens. > But this requires that the code lies in the program space (not in external > library) and the code is compiled with runtime error backtrace (-gl). > Otherwise, the program can only report as deep as it can find. > I don't understand: 1) even if I set the masks, why an empty LCL application generate SIGFPE? It means that somewhere GTK or whatever library *indeed* do things like 1/0, only that they are normally hidden/not reported? 2) I already found the problem in my code which is a like look like: *if tbLog.Down then Y := exp(Y);* And Y is a big number e.g. 2500, which caused floating point overflow. The problem was that the number itself should be Log()ed, so that exp() only restore its original value. That was my bug, but the weird thing is that SIGFPE is generated in unit LCLType on the line that set font height, which is very innocent, and after I commented out the font.Height operation, the SIGFPE slipped to somewhere else, but NEVER on the line that generated it! Could you explain why? and how to locate where the SIGFPE occurred? Thanks! -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130307/6d4b7f70/attachment-0001.html>

Reply by email