strange segfault involving io::readWkt, algorithm::volume and CGAL::Nef_polyhedron_3
Created by: jjpepper
This simple sample program causes a segfault, but commenting out the line which declares a CGAL::Nef_polyhedron_3 in foo() and it all works and outputs "block volume = 1".
My system is RHEL6 building with gcc4.4 and using SFCGAL 1.3.0 and CGAL 4.9. SFCGAL and CGAL built from source. I'm compiling with -frounding-math -g -O0 -std=c++0x
I put the Nef_polyhedron_3 into a separate function to be sure it wasn't a stack issue, but the same problem happens if the call to foo() is replaced with the body of foo(). I get an empty stack with CGAL::internal::intersection is the current stack location. Stack #1 is 0x00 (see output below).
#include <SFCGAL/io/wkt.h>
#include <SFCGAL/PolyhedralSurface.h>
#include <SFCGAL/algorithm/volume.h>
#include <SFCGAL/Solid.h>
#include <CGAL/Nef_polyhedron_3.h>
const std::string block0( "POLYHEDRALSURFACE Z (((0 0 0, 0 1 0, 1 0 0, 0 0 0 )), "
"((0 0 0, 1 0 0, 0 0 1, 0 0 0 )), "
"((0 0 0, 0 0 1, 0 1 0, 0 0 0 )), "
"((1 0 0, 0 1 0, 0 0 1, 1 0 0 )) )" );
void foo()
{
CGAL::Nef_polyhedron_3<SFCGAL::Kernel> n;
}
int main()
{
//::SFCGAL::Solid solid; // This instead of next 2 lines works fine
::std::auto_ptr< ::SFCGAL::Geometry > geometry0( ::SFCGAL::io::readWkt( block0 ) );
::SFCGAL::Solid solid( geometry0->as< ::SFCGAL::PolyhedralSurface >() );
auto vol = ::SFCGAL::algorithm::volume( solid );
std::cerr << "block volume = " << vol << "\n";
foo();
return 0;
}
gdb output:
(gdb) run
Starting program: /home/jesse.j.pepper/tmp/volume
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff751d96e in CGAL::Intersection_traits<CGAL::Simple_cartesian<CGAL::Interval_nt<false> >, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3>::result_type CGAL::internal::intersection<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >(CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3 const&, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3 const&, CGAL::Simple_cartesian<CGAL::Interval_nt<false> > const&) ()
from /home/jesse.j.pepper/git/builder-code/work/rhel6_64-gcc4_4-sfcgal-1_3_0/binaries/lib64/libSFCGAL.so.1
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.x86_64 libgcc-4.4.7-17.el6.x86_64 libstdc++-4.4.7-17.el6.x86_64
(gdb) bt
#0 0x00007ffff751d96e in CGAL::Intersection_traits<CGAL::Simple_cartesian<CGAL::Interval_nt<false> >, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3>::result_type CGAL::internal::intersection<CGAL::Simple_cartesian<CGAL::Interval_nt<false> > >(CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3 const&, CGAL::Simple_cartesian<CGAL::Interval_nt<false> >::Triangle_3 const&, CGAL::Simple_cartesian<CGAL::Interval_nt<false> > const&)
() from /home/jesse.j.pepper/git/builder-code/work/rhel6_64-gcc4_4-sfcgal-1_3_0/binaries/lib64/libSFCGAL.so.1
#1 0x0000000000000000 in ?? ()
(gdb)
Interestingly, running in valgrind shows a CGAL::Assertion_exception being printed out which is not present when running on the command line or in gdb, despite the fact that I am definitely compiling with -frounding-math.
Valgrind output:
[Thu May 25, 17:48:18 ~/tmp jesse.j.pepper@peps (0)]
$ valgrind ./volume
==29016== Memcheck, a memory error detector
==29016== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==29016== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==29016== Command: ./volume
==29016==
terminate called after throwing an instance of 'CGAL::Assertion_exception'
what(): CGAL ERROR: assertion violation!
Expr: -CGAL_IA_MUL(-1.1, 10.1) != CGAL_IA_MUL(1.1, 10.1)
File: /home/jesse.j.pepper/git/mas/builder/3rd/cgal/include/CGAL/Interval_nt.h
Line: 209
Explanation: Wrong rounding: did you forget the -frounding-math option if you use GCC (or -fp-model strict for Intel)?
==29016==
==29016== HEAP SUMMARY:
==29016== in use at exit: 21,095 bytes in 91 blocks
==29016== total heap usage: 110 allocs, 19 frees, 22,865 bytes allocated
==29016==
==29016== LEAK SUMMARY:
==29016== definitely lost: 0 bytes in 0 blocks
==29016== indirectly lost: 0 bytes in 0 blocks
==29016== possibly lost: 1,023 bytes in 7 blocks
==29016== still reachable: 20,072 bytes in 84 blocks
==29016== suppressed: 0 bytes in 0 blocks
==29016== Rerun with --leak-check=full to see details of leaked memory
==29016==
==29016== For counts of detected and suppressed errors, rerun with: -v
==29016== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)
Aborted (core dumped)
=================================================================================
[Thu May 25, 17:48:21 ~/tmp jesse.j.pepper@peps (0)]
$