0xC0000005 error
When I only run the triangle once, there is no problem, and when I run it multiple times, a random error occurs.
This is my code and data, can you please help me see what the problem is?
path1 = r"D:\pdata.txt" path2 = r"D:\index.txt" import numpy as np from triangle import triangulate with open(path1, "r") as f1: data1 = f1.readlines() data2 = [] for i in range(len(data1)): mid = data1[i].strip("\n").split(",") data2.append([float(mid[0]), float(mid[1]), float(mid[2])])
with open(path2, "r") as f2: data3 = f2.readlines() data4 = [] for i in range(len(data3)): mid = data3[i].strip("\n").split(",") data4.append([int(mid[0]), int(mid[1])])
A = dict(vertices=np.delete(data2, 2, axis=1), segments=data4) final_data = [] for i in range(10): final_data.append(triangulate(A, "p"))
I am also getting the segmentation fault while running it on ubuntu. But while running it on windows there is no problem.
import faulthandler
# Enable fault handler
faulthandler.enable()
import triangle as tr
import numpy as np
def delaunay_triangulation(pts, segments):
"""
Apply constrained delaunay triangulation
https://rufat.be/triangle/API.html
"""
pts = np.array(pts[:-1])
segments[-1][1] = 0
t = tr.triangulate({"vertices": pts[:, 0:2], "segments": segments}, 'p')
if 'triangles' not in t:
return []
triangulated_pts = [pts[triangle] for triangle in t['triangles'].tolist()]
return triangulated_pts
boundary_pts = [[1383, 171, 18.0], [1998, 0, 9.170907020568848], [2378, 750, 18.0], [660, 1483, 18.0], [0, 551, 4.605607986450195], [0, 551, 4.605607986450195], [1383, 171, 18.0]]
boundary_segments =[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
for i in range(100):
triangulated_pts = delaunay_triangulation(pts=boundary_pts, segments=boundary_segments)
print(f" is {triangulated_pts}")
faulthandler.disable()
The error i get: Current thread 0x00007fcae2b78740 (most recent call first):
File "/usr/local/lib/python3.8/dist-packages/triangle/tri.py", line 73 in triangulate
File "testtriangle.py", line 15 in delaunay_triangulation
File "testtriangle.py", line 28 in
hello!I have the same problem with you.Have you already solved the problem and how you solved the problem?I sometimes get the error and sometimes run the scripit correctly. 进程已结束,退出代码为 -1073741819 (0xC0000005)
import faulthandler
# Enable fault handler
faulthandler.enable()
import triangle as tr
import numpy as np
def delaunay_triangulation(pts, segments):
"""
Apply constrained delaunay triangulation
https://rufat.be/triangle/API.html
"""
pts = np.array(pts, dtype= float)
_, unique_indices = np.unique(pts, axis=0, return_index=True)
unique_indices = np.sort(unique_indices)
pts = pts[unique_indices]
segments = segments[:len(pts)]
segments[-1][1] = `0`
t = tr.triangulate({"vertices": pts[:, 0:2], "segments": segments}, 'p')
if 'triangles' not in t:
return []
triangulated_pts = [pts[triangle] for triangle in t['triangles'].tolist()]
return triangulated_pts
boundary_pts = [[1383, 171, 18.0], [1998, 0, 9.170907020568848], [2378, 750, 18.0], [660, 1483, 18.0], [0, 551, 4.605607986450195], [0, 551, 4.605607986450195], [1383, 171, 18.0]]
boundary_segments =[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
for i in range(100):
triangulated_pts = delaunay_triangulation(pts=boundary_pts, segments=boundary_segments)
print(f" is {triangulated_pts}")
faulthandler.disable()
I solved this by making pts unique.
Thanks,I have solved the problem through your method.My points are from .shp polygon file which the first polygon point is the same as the last point.I delete the last point and it works!Thank you for your reply!!!