meiyunyang / chipmunk-physics

Automatically exported from code.google.com/p/chipmunk-physics
MIT License
0 stars 0 forks source link

Linux, GCC 4.5.1, segmentation fault #30

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I got strange problem under Linux with Chipmunk. Seems in some situations 
variable dist(in function circle2circleQuery from cpCollision.c) can be equal 
to zero and this cause "division by zero". Adding "if ( dist == 0 ) return 0;" 
before "cpContactInit" solved the problem.

Original issue reported on code.google.com by dr.andru@gmail.com on 9 Dec 2010 at 9:23

GoogleCodeExporter commented 8 years ago
'dist' will be zero of the circles are in the exact same place', but there were 
already conditional expressions protecting against divide by zero. It's strange 
that those didn't catch it. What version of Chipmunk?

Also, are you running this code on a machine without an FPU? Following normal 
floating point rules, a non-zero number divided by zero should evaluate to +/- 
infinity, but not an error. Chipmunk actually uses infinity this way in a 
number of places. If you don't have full FPU support you will have to drop the 
--fast-math flag so that GCC inserts checks for handling infinity and NaN.

Original comment by slemb...@gmail.com on 9 Dec 2010 at 9:37

GoogleCodeExporter commented 8 years ago
>> What version of Chipmunk?
5.3.2 and latest from svn

>> Also, are you running this code on a machine without an FPU?
I ran it on my laptop with Turion X2 Ultra ZM85, OS - ArchLinux x86_64, but 
application compiled as 32-bit.

Original comment by dr.andru@gmail.com on 10 Dec 2010 at 5:26

GoogleCodeExporter commented 8 years ago
Another interesting moment. All works fine with GCC 4.4.4

Original comment by dr.andru@gmail.com on 10 Dec 2010 at 9:43

GoogleCodeExporter commented 8 years ago
Hrm. I guess I'll leave this open a little bit longer in case something else 
pops up.

Original comment by slemb...@gmail.com on 11 Dec 2010 at 5:53

GoogleCodeExporter commented 8 years ago
Compilation with flags "-O2 -march=i686 -ffast-math" instead of "-O3 
-ffast-math" solved the problem O_o

Original comment by dr.andru@gmail.com on 20 Dec 2010 at 1:06

GoogleCodeExporter commented 8 years ago
Hrm. I'm thinking that sounds like a compiler bug. There shouldn't be any 
divide by zeros or uninitialized variables in there to cause any undefined 
behaviour like that. I'm not quite sure how to go about reporting it without 
trying to study the assembly it outputs either to see if it really is a bug.

Original comment by slemb...@gmail.com on 20 Dec 2010 at 3:51