Skip to content
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

segfault again, meshpy.triangle before and after numpy. #8

Open
liubenyuan opened this issue Dec 4, 2014 · 6 comments
Open

segfault again, meshpy.triangle before and after numpy. #8

liubenyuan opened this issue Dec 4, 2014 · 6 comments

Comments

@liubenyuan
Copy link
Contributor

Hi, in the following script, if I put import meshpy.triangle as triangle before import numpy as np, everything goes fine. However, if I put it after numpy, there will be a segfault.

the versions are

ipython-2.3.1
python-2.7.8
numpy-1.9.1

and using the meshpy-git version.

PS, thanks for the help in the mailing list in generating the facet_markers.

from __future__ import division

import meshpy.triangle as triangle
import numpy as np

def round_trip_connect(start, end):
    return [(i, i+1) for i in range(start, end)] + [(end, start)]

def refinement_func(tri_points, area):
    max_area=0.1
    return bool(area>max_area);

def main():
    points = [(1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1), (1, 0)]
    facets = round_trip_connect(0, len(points)-1)
    markers = [2,2,2,2,2,2]

    outter_start = len(points)
    points.extend([(2, 0), (2, 2), (-2, 2), (-2, -2), (2, -2), (2, 0)])
    facets.extend(round_trip_connect(outter_start, len(points) - 1))
    markers.extend([3,3,3,3,3,3])

    # build
    info = triangle.MeshInfo()
    info.set_points(points)
    info.set_holes([(0, 0)])
    info.set_facets(facets, facet_markers=markers)

    #
    mesh = triangle.build(info, refinement_func=refinement_func)

    #
    mesh_points = np.array(mesh.points)
    mesh_tris = np.array(mesh.elements)
    mesh_attr = np.array(mesh.point_markers)

    print mesh_attr

    import matplotlib.pyplot as plt
    plt.triplot(mesh_points[:, 0], mesh_points[:, 1], mesh_tris)
    plt.xlabel('x')
    plt.ylabel('y')
    #
    n = np.size(mesh_attr);
    inner_nodes = [i for i in range(n) if mesh_attr[i]==2]
    outer_nodes = [i for i in range(n) if mesh_attr[i]==3]
    plt.plot(mesh_points[inner_nodes, 0], mesh_points[inner_nodes, 1], 'ro')
    plt.plot(mesh_points[outer_nodes, 0], mesh_points[outer_nodes, 1], 'go')
    plt.axis([-2.5, 2.5, -2.5, 2.5])
    #plt.show()
    #
    fig = plt.gcf()
    fig.set_size_inches(4.2, 4.2)
    plt.savefig('../../figs/sec5-meshpy-triangle-ex5.pdf')

if __name__ == "__main__":
    main()
@inducer
Copy link
Owner

inducer commented Dec 4, 2014

Doesn't crash for me, sorry. My versions are almost exactly the same as yours--Python 2.7.8, numpy 1.9.0rc1.

@inducer
Copy link
Owner

inducer commented Dec 4, 2014

(To be clear--I tried both orders.) meshpy is very dependent on the x87 floating point control word, and when something messes with that, it can easily get confused. That would be my first line of investigation...

Hope that helps.

@liubenyuan
Copy link
Contributor Author

updated, I debug the script with meshpy.triangle placed after numpy, and here are the results,


(gdb) file python2
Reading symbols from python2...(no debugging symbols found)...done.
(gdb) run triangle-ex2.py 
Starting program: /usr/bin/python2 triangle-ex2.py
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007fffefb83287 in insertsegment () from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
(gdb) bt
#0  0x00007fffefb83287 in insertsegment () from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#1  0x00007fffefb83741 in formskeleton () from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#2  0x00007fffefb870e9 in triangulate () from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#3  0x00007fffefb61742 in triangulateWrapper(char*, tMeshInfo&, tMeshInfo&, tMeshInfo&, _object*) ()
   from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#4  0x00007fffefb6a48f in meshpyboost::python::objects::caller_py_function_impl<meshpyboost::python::detail::caller<void (*)(char*, tMeshInfo&, tMeshInfo&, tMeshInfo&, _object*), meshpyboost::python::default_call_policies, meshpyboost::mpl::vector6<void, char*, tMeshInfo&, tMeshInfo&, tMeshInfo&, _object*> > >::operator()(_object*, _object*) () from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#5  0x00007fffefb92e03 in meshpyboost::python::objects::function::call(_object*, _object*) const ()
   from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#6  0x00007fffefb92f1d in meshpyboost::detail::function::void_function_ref_invoker0<meshpyboost::python::objects::(anonymous namespace)::bind_return, void>::invoke(meshpyboost::detail::function::function_buffer&) ()
   from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#7  0x00007fffefba1d2f in meshpyboost::python::handle_exception_impl(meshpyboost::function0<void>) ()
   from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#8  0x00007fffefb9024c in function_call () from /home/postgres/.python-eggs/MeshPy-2014.1-py2.7-linux-x86_64.egg-tmp/meshpy/_triangle.so
#9  0x00007ffff7a58773 in PyObject_Call () from /usr/lib/libpython2.7.so.1.0
#10 0x00007ffff7aedba7 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#11 0x00007ffff7af0a90 in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#12 0x00007ffff7aeefd7 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#13 0x00007ffff7af0a90 in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#14 0x00007ffff7aeefd7 in PyEval_EvalFrameEx () from /usr/lib/libpython2.7.so.1.0
#15 0x00007ffff7af0a90 in PyEval_EvalCodeEx () from /usr/lib/libpython2.7.so.1.0
#16 0x00007ffff7af0b89 in PyEval_EvalCode () from /usr/lib/libpython2.7.so.1.0
#17 0x00007ffff7b09fef in run_mod () from /usr/lib/libpython2.7.so.1.0
#18 0x00007ffff7b0b212 in PyRun_FileExFlags () from /usr/lib/libpython2.7.so.1.0
#19 0x00007ffff7b0c427 in PyRun_SimpleFileExFlags () from /usr/lib/libpython2.7.so.1.0
#20 0x00007ffff7b1d7ca in Py_Main () from /usr/lib/libpython2.7.so.1.0
#21 0x00007ffff746f040 in __libc_start_main () from /usr/lib/libc.so.6
#22 0x000000000040073e in _start ()

and using

python2 -m pdb triangle-ex2.py

I found this problem might be related with the refinement_func. I can not go any further here and do not know whether I would help in solving this problem.

@inducer
Copy link
Owner

inducer commented Dec 8, 2014

Did you change the script in your original report?

@liubenyuan
Copy link
Contributor Author

Yes, I remove all the markers and remove some plot commands in drawing the boundary nodes.

from __future__ import division

import meshpy.triangle as triangle
import numpy as np

def round_trip_connect(start, end):
    return [(i, i+1) for i in range(start, end)] + [(end, start)]

def refinement_func(tri_points, area):
    max_area=0.1
    return bool(area>max_area);

def main():
    points = [(1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1), (1, 0)]
    facets = round_trip_connect(0, len(points)-1)

    outter_start = len(points)
    points.extend([(2, 0), (2, 2), (-2, 2), (-2, -2), (2, -2), (2, 0)])
    facets.extend(round_trip_connect(outter_start, len(points)-1))

    # build
    info = triangle.MeshInfo()
    info.set_points(points)
    info.set_holes([(0, 0)])
    info.set_facets(facets)

    #
    mesh = triangle.build(info, refinement_func=refinement_func)

    #
    mesh_points = np.array(mesh.points)
    mesh_tris = np.array(mesh.elements)
    mesh_attr = np.array(mesh.point_markers)

    import matplotlib.pyplot as plt
    plt.triplot(mesh_points[:, 0], mesh_points[:, 1], mesh_tris)
    plt.xlabel('x')
    plt.ylabel('y')
    #
    fig = plt.gcf()
    fig.set_size_inches(4.2, 4.2)
    plt.savefig('../../figs/sec5-meshpy-triangle-ex2.pdf')

if __name__ == "__main__":
    main()

@inducer
Copy link
Owner

inducer commented Dec 10, 2014

Doesn't crash for me, sorry. :/

chrisk314 added a commit to chrisk314/mesh-sphere-packing that referenced this issue Jan 22, 2018
Issues with segfaults in meshpy.triangle related to order of of meshpy
vs. numpy imports have emerged again. See this issue on the meshpy repo
(inducer/meshpy#8).

Look into using TetGen to do the 2d triangulation as the issue seems to
be restricted to triangle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants