pyvista-support icon indicating copy to clipboard operation
pyvista-support copied to clipboard

"Windows fatal exception: access violation" when calling `decimate`

Open nidu opened this issue 3 years ago • 10 comments

Description

When calling a series of delaunay, clip_box and decimate on a point cloud - i'm getting "Windows fatal exception: access violation" sometimes, more precisely:

Windows fatal exception: access violation

Current thread 0x00003ae8 (most recent call first):
  File "C:\Users\kally\anaconda3\envs\geo\lib\site-packages\pyvista\core\filters.py", line 47 in _update_alg
  File "C:\Users\kally\anaconda3\envs\geo\lib\site-packages\pyvista\core\filters.py", line 2914 in decimate
--------------------------------------------------------------------------------
  Date: Tue Aug 11 23:14:16 2020 W. Europe Daylight Time

                OS : Windows
            CPU(s) : 12
           Machine : AMD64
      Architecture : 64bit
       Environment : Python

  Python 3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]

             numpy : 1.18.5
             scipy : 1.5.0
           IPython : 7.16.1
        matplotlib : 3.2.2
            scooby : 0.5.6

  Intel(R) Math Kernel Library Version 2020.0.1 Product Build 20200208 for
  Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

Example Data

I can reproduce it with this file:

import pyvista as pv

print('Generate hills')
m = pv.ParametricRandomHills().extract_geometry()
print(f'Triangulate {m.n_points} points')
m = m.delaunay_2d()
print(f'Clip box {m.n_points} points, {m.n_faces} faces')
m = m.clip_box((-10, 0, -10, 0, -10, 0), invert=False).extract_geometry()
print(f'Decimate {m.n_points} points, {m.n_faces} faces')
m = m.decimate(.99)

The output is

Generate hills
Triangulate 10000 points
Clip box 10000 points, 19643 faces
Decimate 156 points, 151 faces
Windows fatal exception: access violation

Current thread 0x00000d74 (most recent call first):
  File "C:\Users\kally\anaconda3\envs\geo\lib\site-packages\pyvista\core\filters.py", line 47 in _update_alg
  File "C:\Users\kally\anaconda3\envs\geo\lib\site-packages\pyvista\core\filters.py", line 2914 in decimate
  File ".\error_report.py", line 10 in <module>

nidu avatar Aug 11 '20 21:08 nidu

This seems related to https://github.com/pyvista/pyvista/issues/861... @pyvista/developers, this is concerning that we've had two Windows users recently report the Windows fatal exception: access violation error.

@nidu, can you please share a PyVista report (you shared a scooby default report which doesn't show details about PyVista)? print(pv.Report(gpu=False)) (gpu=False to avoid any errors)

banesullivan avatar Aug 13 '20 23:08 banesullivan

My immediate advice, I suspect you are using the latest version of VTK (9.x). Please try downgrading VTK to 8.1.2 and see if the error happens still

banesullivan avatar Aug 13 '20 23:08 banesullivan

Here's the info from pv.Report(gpu=False)

--------------------------------------------------------------------------------
  Date: Fri Aug 14 07:59:24 2020 W. Europe Daylight Time

                OS : Windows
            CPU(s) : 12
           Machine : AMD64
      Architecture : 64bit
       Environment : Python
       GPU Details : None

  Python 3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]

           pyvista : 0.25.3
               vtk : 8.2.0
             numpy : 1.18.5
           imageio : 2.9.0
           appdirs : 1.4.3
            scooby : 0.5.6
            meshio : 4.0.16
        matplotlib : 3.2.2
             PyQt5 : 5.12.3
           IPython : 7.16.1
             scipy : 1.5.0

  Intel(R) Math Kernel Library Version 2020.0.1 Product Build 20200208 for
  Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

nidu avatar Aug 14 '20 06:08 nidu

Hi, small update. I could set up WSL 2 on my machine, installed pyvista there, but i get similar error with the example above, so probably it's not Windows specific (if WSL 2 is a good enough approximation to Linux).

Generate hills
Triangulate 10000 points
Clip box 10000 points, 19643 faces
Decimate 156 points, 151 faces
Fatal Python error: Segmentation fault

Current thread 0x00007f27aa053740 (most recent call first):
  File "/home/nidu/miniconda3/envs/geo/lib/python3.8/site-packages/pyvista/core/filters.py", line 47 in _update_alg
  File "/home/nidu/miniconda3/envs/geo/lib/python3.8/site-packages/pyvista/core/filters.py", line 2914 in decimate
  File "case_229.py", line 10 in <module>
Segmentation fault
--------------------------------------------------------------------------------
  Date: Sat Aug 22 19:59:25 2020 CEST

                OS : Linux
            CPU(s) : 12
           Machine : x86_64
      Architecture : 64bit
       Environment : Python
       GPU Details : None

  Python 3.8.5 (default, Aug  5 2020, 08:36:46)  [GCC 7.3.0]

           pyvista : 0.25.3
               vtk : 8.2.0
             numpy : 1.19.1
           imageio : 2.9.0
           appdirs : 1.4.4
            scooby : 0.5.6
            meshio : 4.1.0
             scipy : 1.5.2

  Intel(R) Math Kernel Library Version 2020.0.1 Product Build 20200208 for
  Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

nidu avatar Aug 22 '20 17:08 nidu

One more update. If I remove clip_box - it works fine, so the problem is there. I tried to copy mesh or create a new mesh based on copied points and faces, but it didn't help. So then i looked at points and faces and found that a lot of faces has one point listed twice in a single triangle. For example this code

import pyvista as pv

print('Generate hills')
m = pv.ParametricRandomHills().extract_geometry()
print(f'Triangulate {m.n_points} points')
m = m.delaunay_2d()
print(f'Clip box {m.n_points} points, {m.n_faces} faces')
m = m.clip_box((-10, 0, -10, 0, -10, 0), invert=False).extract_geometry()

print(f'Remove bad faces')
f = m.faces.reshape(-1, 4)
v1, v2, v3 = [f[:,i] for i in [1, 2, 3]]
bad_faces_cond = (v1 == v2) | (v1 == v3) | (v2 == v3)
bad_faces = f[bad_faces_cond]
bad_faces

shows this:

Generate hills
Triangulate 10000 points
Clip box 10000 points, 19643 faces
Remove bad faces
array([[  3,   1,   3,   3],
       [  3,   4,   5,   5],
       [  3,   7,   8,   8],
       [  3,  10,  11,  11],
       [  3,  13,  14,  14],
       [  3,  16,  17,  17],
...

If I remove these points, create a new mesh and decimate it - it works fine. With code like this for example:

import pyvista as pv

print('Generate hills')
m = pv.ParametricRandomHills().extract_geometry()
print(f'Triangulate {m.n_points} points')
m = m.delaunay_2d()
print(f'Clip box {m.n_points} points, {m.n_faces} faces')
m = m.clip_box((-10, 0, -10, 0, -10, 0), invert=False).extract_geometry()

print(f'Remove bad faces')
f = m.faces.reshape(-1, 4)
v1, v2, v3 = [f[:,i] for i in [1, 2, 3]]
bad_faces_cond = (v1 == v2) | (v1 == v3) | (v2 == v3)
bad_faces = f[bad_faces_cond]
print(f'Bad faces: {len(bad_faces)}')
faces = f[~bad_faces_cond].flatten()
m = pv.PolyData(m.points, faces)

print(f'Decimate {m.n_points} points, {m.n_faces} faces')
m.decimate(.9)

And indeed this simple piece of code works fine:

import pyvista as pv
import numpy as np

m = pv.PolyData(np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]]), np.array([3, 0, 1, 2]))
m.decimate(.9)

but this one crashes with access violation (notice one more face)

import pyvista as pv
import numpy as np

m = pv.PolyData(np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]]), np.array([3, 0, 1, 2, 3, 0, 2, 2]))
m.decimate(.9)

One interesting thing for me is that face 0, 1, 1 doesn't crash unlike 0, 2, 2.

nidu avatar Aug 22 '20 21:08 nidu

Thanks for looking into this @nidu! Many of the pyvista developers/maintainers have been busy with our day jobs, so sorry for the late follow-up.

It appears that running clean fixeds this sort of problem:

>>> mesh = pv.PolyData(np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]]),
                       np.array([3, 0, 1, 2, 3, 0, 3, 3]))
>>> mout = mesh.clean()
>>> print(mout.faces)
array([3, 0, 1, 2])

We can consider adding a note to decimate indicating that segmentation faults can be prevented by running clean beforehand. I'm hesitant to run clean always since it can take a long time to execute.

akaszynski avatar Aug 23 '20 02:08 akaszynski

@akaszynski thanks, clean is much cleaner than what i came up with!

nidu avatar Aug 23 '20 08:08 nidu

I've got one

Windows fatal exception: access violation

Current thread 0x00006208 (most recent call first): File "C:\Users\rscott\AppData\Local\Continuum\anaconda3\envs\gempy\lib\site-packages\pyvista\plotting\renderer.py", line 1090 in reset_camera File "C:\Users\rscott\AppData\Local\Continuum\anaconda3\envs\gempy\lib\site-packages\pyvista\plotting\renderer.py", line 377 in add_actor File "C:\Users\rscott\AppData\Local\Continuum\anaconda3\envs\gempy\lib\site-packages\pyvista\plotting\plotting.py", line 335 in add_actor File "C:\Users\rscott\AppData\Local\Continuum\anaconda3\envs\gempy\lib\site-packages\pyvista\plotting\plotting.py", line 1354 in add_mesh File "C:\Users\rscott\AppData\Local\Continuum\anaconda3\envs\gempy\lib\site-packages\pyvista\plotting\helpers.py", line 113 in plot File "test.py", line 187 in

I think it is related to faces though, e.g. from the tsurf test - I haven't checked them to make sure they all make sense, but not your usual error

RichardScottOZ avatar Mar 05 '21 11:03 RichardScottOZ

e.g. https://github.com/pyvista/pyvista/issues/4902

RichardScottOZ avatar Mar 05 '21 11:03 RichardScottOZ

yeah, this is apparently because need another dimension to say the triangle is a triangle at the start!

RichardScottOZ avatar Mar 05 '21 11:03 RichardScottOZ