I’m using pygame with python to dable in game development and I just hit a brick wall. When one of my entities attempts to move using Vector2 multiplication I get “Fatal Python error: (pygame parachute) Segmentation Fault”.
The immediate code around the error is this:
# 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)
The following may be helpful as well. You can reproduce the issue I’m having by typing the following into a python intepreter (Python 2.7 and 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
The full code to reproduce the issue can be found here:
http://ftp.mattwjones.net
username: share1
password: !share1
It only crashes for me with in-place addition. v = v + v2 works fine. (Python 3.2, pygame 1.9.2pre).
I don’t see anything obviously wrong in math.c,
vector_generic_math, but based on my experiments it seems there’s a pointer bug somewhere. You should submit a bug report.