问题描述
我有一个 python 脚本,它不是我写的,它使用了 vtk 模块.它适用于我的旧 iMac 和我的 Linux 机器.在安装了 OS X Mavericks 的 Macbook Pro 上尝试时,在渲染过程中出现段错误.我已经追踪到调用 vtkRender() 方法的错误,该方法导致脚本因 seg fault 11 崩溃.我真的不知道如何进一步找出错误的确切原因(例如,怎么做我使用 pdb 进入方法调用?),有什么想法吗?
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?
最小的程序崩溃如下:
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
更新:我在 VirtualBox 上安装了 Ubuntu,并且在上面的示例中遇到了相同的段错误,但是我的使用 vtk 模块的 python 脚本工作得很好.
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.
所以这似乎是使用 EPD 和 OS X Mavericks 提供的 VTK 包的问题.知道如何解决这个问题吗?我删除了 VTK 的所有痕迹并尝试从源代码安装,但在这种情况下,我遇到了各种各样的问题,只是让 VTK 导入.
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.
更新:
通过向脚本中的 VTK 代码添加一些额外的样板,我可以让它再次工作.确实很奇怪的行为.在具有相同代码和库的 Ubuntu 中工作正常,但在 Mac OS X 上它会出现分段错误,除非我向渲染对象添加一些 .Initialize() 方法调用和其他方法调用.
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.
推荐答案
在渲染之前,您应该创建一个渲染窗口并添加渲染器.另外,调用 render-window 的 Render()
方法,而不是渲染器的方法.
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()
这篇关于vtk.vtkRender() 导致段错误:11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!