2011-08-19 35 views
1

我在游戏开发中使用pygame与python导致了dable,我只是碰到了一堵砖墙。当我的一个实体尝试移动使用Vector2乘法时,我得到“致命的Python错误:(pygame降落伞)分段错误”。Vector2乘法导致蟒蛇中的分割错误

周围的错误时立即代码是这样的:

# 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) 

下可能有帮助。您可以复制,我通过键入以下为蟒蛇intepreter遇到的问题(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

+0

具体来说,在第一类'game_base.py'的第三种方法中,在'Zombies !!!'文件夹中。 – agf

+0

哈!!!果然,这是做到了。我用“self.location = self.location + travel_distance * heading”替换了“self.location + = travel_distance * heading”,现在我的游戏运行良好。 Eryksun,添加与该信息的答复,我会接受它作为答案。 – viper34j

+0

这应该作为对pygame IMO的错误提交。 –

回答

1

它只是在原地添加崩溃。 v = v + v2工作正常。 (Python 3.2,pygame 1.9.2pre)。

我在math.c,vector_generic_math中没有看到任何明显的错误,但是根据我的实验,似乎在某处存在指针错误。你应该提交一个错误报告。

+0

提交错误报告,感谢您的帮助。 – viper34j