python - Vector2 乘法导致 python 中的段错误

标签 python pygame

我正在使用 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/

相关文章:

python - 类型错误 : argument 1 must be pygame. 表面,而不是 pygame.Rect

python - 如何找到最近的可能的开放位置进行 pygame 碰撞检测?

python - 计算一个元素在多个列表中的出现次数

python - 将 Pandas 列中的数字与日期分开

python - 如何在pygame中生成随机矩形并使它们像飞扬的小鸟一样移动?

python - 使用不正确的文件扩展名将图像读入 pygame

python - 索引错误: list index out of range on a walking character

python - 打印 "EXTERNSHEET(b7-):" Pandas

python - 400 万以下的斐波那契数列

python - 使用 pyinstaller 时 Unidecode 不一致的行为