vtk.vtkRender() causes seg fault:11

你离开我真会死。 提交于 2019-12-10 14:30:18

问题


I have a python script, which I didn't write, that utilises the vtk module. It has worked on my old iMac and on my Linux machines. Trying it on my Macbook Pro with OS X Mavericks installed I get a seg fault during rendering. I have tracked down the error to a call to the vtkRender() method which causes the script to crash with seg fault 11. I literally have no idea how to go further and find out the exact cause of the bug (for instance, how do I step into a method call using pdb?), any ideas?

A minimal program crash is as follows:

Enthought Canopy Python 2.7.3 | 64-bit | (default, Aug  8 2013, 05:37:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
>>> test = vtk.vtkRenderer()
>>> test.Render()
Segmentation fault: 11

Update: I installed Ubuntu on VirtualBox and get the same seg fault for the above example, however my python script utilising the vtk modules works just fine.

So this seems to be a problem using the VTK package provided with EPD and OS X Mavericks. Any idea how to fix this? I deleted all trace of VTK and tried installing from source but I'm having all manner of problems just getting VTK to import in this case.

Update:

By adding some extra boiler-plate to the VTK code in the script I can get it to work again. Very strange behaviour indeed. Works fine in Ubuntu with identical code and libraries, yet on Mac OS X it seg faults unless I add some .Initialize() method calls and others to the rendering object.


回答1:


When I installed OS X Mavericks, I thought that everything had made it through the install without being broken. My python install was broken though. Installing the release candidate of Python 2.7.6 fixed the issue for me. There's also a patch to fix the segfault issue floating around for 2.7.5 on Mavericks.




回答2:


You should create a render-window and add the renderer to it before rendering. Also, call the render-window's Render() method, not the renderer's.

import vtk
rr = vtkRenderer()
rw = vtkRenderWindow()
rw.AddRenderer(rr)
rw.Render()


来源:https://stackoverflow.com/questions/19862573/vtk-vtkrender-causes-seg-fault11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!