2011-08-19 82 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