Skip to content

3D Alpha Wrapping segfault with gcc 15.1 and inline activated #8876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ptitjano opened this issue May 7, 2025 · 3 comments
Closed

3D Alpha Wrapping segfault with gcc 15.1 and inline activated #8876

ptitjano opened this issue May 7, 2025 · 3 comments

Comments

@ptitjano
Copy link

ptitjano commented May 7, 2025

Issue Details

When using 3D Alpha Wrapping on the bunny dataset with GCC 15.1, a segmentation fault occurs as soon as an optimization level is activated. Disabling inline fixes the issue. This problem does not occur with GCC 14.

Source Code

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/alpha_wrap_3.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/Real_timer.h>

#include <iostream>
#include <string>

using InexactKernel   = CGAL::Exact_predicates_inexact_constructions_kernel;
using Inexact_Point_3 = InexactKernel::Point_3;
using Mesh            = CGAL::Surface_mesh<Inexact_Point_3>;


int main(int argc, char** argv)
{
  // read the input
  std::list<Inexact_Point_3> points;

  //read input
  std::ifstream inputStream("bunny_1000");
  int nrPoints;
  inputStream >> nrPoints;
  std::cout << "Reading " << nrPoints << " points " << std::endl;
  Inexact_Point_3 point;
  for( ; nrPoints>0 ; nrPoints--)
  {
    inputStream >> point;
    points.push_back(point);
  }

  std::cout << points.size() << " points" << std::endl;

  // Compute the alpha and offset values
  const double relativeAlpha = 20.;

  CGAL::Bbox_3 bbox = CGAL::bbox_3(std::cbegin(points), std::cend(points));
  const double diag_length = std::sqrt(CGAL::square(bbox.xmax() - bbox.xmin()) +
                                       CGAL::square(bbox.ymax() - bbox.ymin()) +
                                       CGAL::square(bbox.zmax() - bbox.zmin()));
  const double alpha = diag_length / relativeAlpha;
  std::cout << "diag length = " << diag_length << "\n";
  std::cout << "relative alpha = " << relativeAlpha << "\n";
  std::cout << "absolute alpha = " << alpha << "\n";

  // Construct the wrapMesh
  CGAL::Real_timer timer;
  timer.start();

  Mesh wrapMesh;
  CGAL::alpha_wrap_3(points, alpha, wrapMesh);

  timer.stop();
  std::cout << "Result: " << num_vertices(wrapMesh) << " vertices, " << num_faces(wrapMesh) << " faces" << std::endl;
  std::cout << "Took " << timer.time() << " s." << std::endl;

  // Save the result
  const std::string output_name = "output_bunny.off";
  std::cout << "Writing to " << output_name << std::endl;
  CGAL::IO::write_polygon_mesh(output_name, wrapMesh, CGAL::parameters::stream_precision(17));

  return EXIT_SUCCESS;
}

with inline

g++ -Wall -O1 main_cgal.cpp -lgmp -lgmpxx -lmpfr -o main_cga
Reading 1000 points 
1000 points
diag length = 0.248131
relative alpha = 20
absolute alpha = 0.0124066
terminate called after throwing an instance of 'CGAL::Assertion_exception'
  what():  CGAL ERROR: assertion violation!
Expr: n == N[3]
File: /usr/include/CGAL/Triangulation_ds_cell_base_3.h
Line: 122
Aborted (core dumped)

without inline

g++ -Wall -O1 -fno-inline main_cgal.cpp -lgmp -lgmpxx -lmpfr -o main_cgal
Reading 1000 points 
1000 points
diag length = 0.248131
relative alpha = 20
absolute alpha = 0.0124066
Result: 1193 vertices, 2386 faces
Took 0.788322 s.
Writing to output_bunny.off

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): can reproduce on windows with mingw and fedora 42
  • Compiler: gcc 15.1
  • Release or debug mode: Release
  • Specific flags used (if any): 01/02/03
  • CGAL version: 6.0.1
  • Boost version: 1.83
  • Other libraries versions if used (Eigen, TBB, etc.): N/A
lbartoletti pushed a commit to Oslandia/SFCGAL_CI that referenced this issue May 7, 2025
With inline enabled CGAL::alpha_wrap_3 may segfault with GCC 15.

See: CGAL/cgal#8876
@sloriot
Copy link
Member

sloriot commented May 7, 2025

I think we already fixed the issue in master. Could you give it a try?

@sloriot
Copy link
Member

sloriot commented May 7, 2025

More precisely here: #8820

lbartoletti pushed a commit to Oslandia/SFCGAL_CI that referenced this issue May 7, 2025
With inline enabled CGAL::alpha_wrap_3 may segfault with GCC 15.
This is fixed on current CGAL master.

See: CGAL/cgal#8876
@ptitjano
Copy link
Author

ptitjano commented May 7, 2025

Thanks for the quick answer. This is indeed fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants