我正在使用 pygame 和 python 来进行游戏开发,但我遇到了困难。当我的一个实体尝试使用 Vector2 乘法移动时,我收到“致命 Python 错误:(pygame 降落伞)段错误”。
围绕错误的直接代码是这样的:
# destination and location are Vector2, and the difference is a Vector2
vec_to_destination = self.destination - self.location
distance_to_destination = vec_to_destination.length()
# normalize() returns a Vector2
heading = vec_to_destination.normalize()
# time_passed is a float and speed is an int
travel_distance = min(distance_to_destination, time_passed * self.speed)
# location is a Vector2 as well.
self.location += travel_distance * heading
# The previous line is where the Segmentation fault occurs.
# The equation looks like this with values filled in:
# Vector2(747, 183) += 6.435 * Vector2(-0.882763, 0.469818)
以下内容可能也会有所帮助。您可以通过在 python 解释器中输入以下内容来重现我遇到的问题(Python 2.7 和 pygame 1.9.2pre):
import pygame
from pygame.math import *
v = Vector2(747, 183)
v2 = 6.435 * Vector2(-0.882763, 0.469818)
v += v2
v
可以在此处找到重现该问题的完整代码: ftp.mattwjones.net 用户名:share1 密码:!share1
最佳答案
它只会在就地添加时崩溃。 v = v + v2 工作正常。 (Python 3.2,pygame 1.9.2pre)。
我在 math.c 中没有发现任何明显错误,vector_generic_math
,但根据我的实验,某处似乎存在指针错误。您应该提交错误报告。
关于python - Vector2 乘法导致 python 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7116813/