尝试获取纹理区域时出现分段错误

问题描述 投票:0回答:1

我创建了一个简单的函数,从给定的图像返回一个纹理区域:

from kivy.core.image import Image


def get_figure_texture(figure: Figure, img_path: str):
image = Image(img_path).texture
figures = {
    'white': {
        'king': (0, 0),
        'queen': (64, 0),
        'rook': (128, 0),
        'knight': (192, 0),
        'bishop': (256, 0),
        'pawn': (320, 0)
    },
    'black': {
        'king': (0, 64),
        'queen': (64, 64),
        'rook': (128, 64),
        'knight': (192, 64),
        'bishop': (256, 64),
        'pawn': (320, 64)
    }
}
offset = figures[figure.color_name][figure.name]

return image.texture.get_region(offset[0], offset[1], 64, 64)

然后,我想创建一个纹理:

 figure = Figure
 figure.name = 'king'
 figure.color_name = 'white'
 figure.texture - get_figure_texture(figure, 'res/figures.png')

当Kivy尝试从给定路径创建图像时,我会在日志中得到这个:

[INFO   ] [Logger      ] Record log in 
/home/celtic/.kivy/logs/kivy_18-03-04_7.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pygame, 
img_gif (img_pil, img_ffpyplayer ignored)
/home/celtic/PycharmProjects/pygame-
tutorial/venv/lib/python3.6/importlib/_bootstrap.py:219: 
ImportWarning: can't resolve package from __spec__ or __package__, 
falling back on __name__ and __path__
return f(*args, **kwds)
Fatal Python error: (pygame parachute) Segmentation Fault

图像是384 x 128,我提供的路径是正确的,因为对于其他路径我得到错误:AttributeError: 'NoneType' object has no attribute 'tell'

python python-3.x pygame kivy
1个回答
0
投票
  1. Kivy的pygame后端已被弃用,请尝试使用sdl2。
  2. 如果这是您实际代码的良好表示,请尝试在顶部添加from kivy.core.window import Window
© www.soinside.com 2019 - 2024. All rights reserved.