Kivy代码分段错误

时间:2014-09-20 22:23:33

标签: python segmentation-fault kivy

有没有人知道为什么这段代码会出现分段错误?

来自 nodeapp.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout

class Node(Widget):

    def __init__(self):
        pass

    inputs = 1
    function = "add"



class NodeApp(App):

    def build(self):

        fl = FloatLayout()
        nod = Node()

        fl.add_widget(nod)
        return fl

if __name__ == '__main__':
    NodeApp().run()

来自 node.kv

<Node>:
    size: 0.5,0.5
    canvas:
        Rectangle:
            pos: 1,1

日志:

botstrapping Kivy @ D:\CPPP\
Setting Environment Variables:
#################################
GST_REGISTRY
D:\CPPP\gstreamer\registry.bin
---------------
GST_PLUGIN_PATH:
D:\CPPP\gstreamer\lib\gstreamer-1.0
---------------
PATH:
D:\CPPP\;D:\CPPP\Python27;D:\CPPP\tools;D:\CPPP\Python27\Scripts;D:\CPPP\gstream
er\bin;D:\CPPP\MinGW\bin;C:\Program Files\CollabNet\Subversion Client;C:\Program
 Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows
;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\AMD\ATI
.ACE\Core-Static;C:\Program Files\MATLAB\MATLAB Compiler Runtime\v81\runtime\win
64;C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v81\runtime\win32;D:\no
dejs\;C:\Python27\;C:\Program Files (x86)\Wiimm\WIT;C:\Program Files (x86)\ATI T
echnologies\ATI.ACE\Core-Static;C:\Program Files\Common Files\Microsoft Shared\W
indows Live;C:\Program Files (x86)\Nmap;C:\Users\a\AppData\Roaming\npm;C:\Python
27\;C:\Program Files (x86)\Wiimm\WIT
----------------------------------
PYTHONPATH:
D:\CPPP\kivy;
----------------------------------
##################################
done bootstraping kivy...have fun!\n
running "python.exe D:\CPPP\nodeapp.py" \n
[INFO              ] Kivy v1.8.0
[INFO              ] [Logger      ] Record log in C:\Users\a\.kivy\logs\kivy_14-
09-20_78.txt
[INFO              ] [Factory     ] 157 symbols loaded
[DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=
Nones
[DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout
=60s
[DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout
=Nones
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_pygame, img
_gif (img_pil ignored)
[DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeo
ut=60s
[DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeou
t=3600s
[INFO              ] [Text        ] Provider: pygame
[DEBUG             ] [App         ] Loading kv <D:\CPPP\node.kv>
[DEBUG             ] [Window      ] Ignored <egl_rpi> (import error)
[INFO              ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)

[DEBUG             ] [Window      ] Display driver windib
[DEBUG             ] [Window      ] Actual window size: 800x600
[DEBUG             ] [Window      ] Actual color bits r8 g8 b8 a8
[DEBUG             ] [Window      ] Actual depth bits: 24
[DEBUG             ] [Window      ] Actual stencil bits: 8
[DEBUG             ] [Window      ] Actual multisampling samples: 2
GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <4.4.12967 Compatibility Prof
ile Context 14.200.1004.0>
[INFO              ] [GL          ] OpenGL vendor <ATI Technologies Inc.>
[INFO              ] [GL          ] OpenGL renderer <AMD Radeon HD 7800 Series>
[INFO              ] [GL          ] OpenGL parsed version: 4, 4
[INFO              ] [GL          ] Shading version <4.40>
[INFO              ] [GL          ] Texture max size <16384>
[INFO              ] [GL          ] Texture max units <32>
[DEBUG             ] [Shader      ] Fragment compiled successfully
[DEBUG             ] [Shader      ] Vertex compiled successfully
[DEBUG             ] [ImagePygame ] Load <D:\CPPP\kivy\kivy\data\glsl\default.pn
g>
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, n
ot docked
Fatal Python error: (pygame parachute) Segmentation Fault

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Press any key to continue . . .

谷歌搜索问题导致我更新我的显卡驱动程序(现在是14.7 RC,最新版本)并使用ensure_window(),这两个都没有解决问题。

注释__init__解决了分段错误,但阻止我使用__init__进行任何操作

1 个答案:

答案 0 :(得分:4)

我还没有检查到底出了什么问题,但问题可能是被覆盖的__init__ 没有调用该类的原始__init__,这很重要因为这会设置所有正常的kivy行为,包括给小部件画布等。

你至少应该这样做:

def __init__(self):
    super(Node, self).__init__()