Kivy代码分段错误

use*_*723 3 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()
Run Code Online (Sandbox Code Playgroud)

来自node.kv

<Node>:
    size: 0.5,0.5
    canvas:
        Rectangle:
            pos: 1,1
Run Code Online (Sandbox Code Playgroud)

日志:

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 . . .
Run Code Online (Sandbox Code Playgroud)

搜寻该问题导致我更新了显卡驱动程序(现在为最新版本14.7 RC),并使用了sure_window(),但这两种方法都无法解决问题。

注释掉__init__可以解决分段错误,但是会阻止我使用__init__进行任何操作

inc*_*ent 5

我没有检查究竟是什么出了问题,但问题是可能是你的重写__init__没有调用原始__init__类的,这是非常重要的,因为这将设置所有正常kivy行为,包括给予小部件帆布等。

您应该至少执行以下操作:

def __init__(self):
    super(Node, self).__init__()
Run Code Online (Sandbox Code Playgroud)