Crash in 2D boolean difference

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Crash in 2D boolean difference

tfmk
Hello,

I've encountered a crash in a very simple case of 2D boolean operations.
My CGAL version is 5.0 (CGAL_VERSION_NR = 1050000000), but I noticed the
same problem in version 4.7.
To build the project, my CMakeLists.txt contains just the standard
"find_package(CGAL)" as generated by
the cgal_create_CMakeLists script. Adding -frounding-math and/or setting
-O0/-O1/-O2 doesn't help.
I'm using the header-only version of CGAL.
My OS: Ubuntu 16.04 LTS
My compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)

What should I do to prevent this crash? Could this be a bug in CGAL or is my
setup wrong?

Here is the minimal example of a crashing program:

// START OF EXAMPLE
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Polygon_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Point_2<Kernel>                             Point_2;
typedef CGAL::Polygon_2<Kernel>                           Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel>                HPolygon_2;

int main()
{
        Point_2 points[] = {
                {-0.0541739, -1.74445},
                {-0.820393, -1.08577},
                {-2.83145, -2.79697},
                {0.894224, -0.747698},
                {-1.88305, -1.80022},
                {0.180497, -2.65798},
        };
        Polygon_2 polys[2];
        polys[0].push_back(points[0]);
        polys[0].push_back(points[1]);
        polys[0].push_back(points[2]);
        polys[1].push_back(points[3]);
        polys[1].push_back(points[4]);
        polys[1].push_back(points[5]);

        HPolygon_2 finalPoly(polys[0]);
        CGAL::difference(finalPoly, polys[1], &finalPoly); // CRASHES HERE
        return 0;
}
// END OF EXAMPLE



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Crash in 2D boolean difference

Efi Fogel
The result consists of 2 polygons with holes.
Change
        HPolygon_2 finalPoly(polys[0]);
        CGAL::difference(finalPoly, polys[1], &finalPoly);
to
        std::list<HPolygon_2> res;
        CGAL::difference(pgn1, pgn2, std::back_inserter(res));

   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Mon, 1 Apr 2019 at 12:03, tfmk <[hidden email]> wrote:
Hello,

I've encountered a crash in a very simple case of 2D boolean operations.
My CGAL version is 5.0 (CGAL_VERSION_NR = 1050000000), but I noticed the
same problem in version 4.7.
To build the project, my CMakeLists.txt contains just the standard
"find_package(CGAL)" as generated by
the cgal_create_CMakeLists script. Adding -frounding-math and/or setting
-O0/-O1/-O2 doesn't help.
I'm using the header-only version of CGAL.
My OS: Ubuntu 16.04 LTS
My compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)

What should I do to prevent this crash? Could this be a bug in CGAL or is my
setup wrong?

Here is the minimal example of a crashing program:

// START OF EXAMPLE
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Polygon_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Point_2<Kernel>                             Point_2;
typedef CGAL::Polygon_2<Kernel>                           Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel>                HPolygon_2;

int main()
{
        Point_2 points[] = {
                {-0.0541739, -1.74445},
                {-0.820393, -1.08577},
                {-2.83145, -2.79697},
                {0.894224, -0.747698},
                {-1.88305, -1.80022},
                {0.180497, -2.65798},
        };
        Polygon_2 polys[2];
        polys[0].push_back(points[0]);
        polys[0].push_back(points[1]);
        polys[0].push_back(points[2]);
        polys[1].push_back(points[3]);
        polys[1].push_back(points[4]);
        polys[1].push_back(points[5]);

        HPolygon_2 finalPoly(polys[0]);
        CGAL::difference(finalPoly, polys[1], &finalPoly); // CRASHES HERE
        return 0;
}
// END OF EXAMPLE



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Crash in 2D boolean difference

tfmk
Thank you very much, this solved the problem.



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss