Just needed to add following to Entity constructor. (why does it work on Windows even without?)
def __init__(self):
sf.Drawable.__init__(self)
The following code works fine on windows machine, but I get segfault when trying to get it run on Arch Linux.
Am I doing something wrong or why does this happen?
import random
import sfml as sf
width = 1280
height = 720
class Entity(sf.Drawable):
def __init__(self, position):
self.shape = sf.CircleShape()
self.shape.radius = 20
r = 55 + random.randrange(200)
g = 55 + random.randrange(200)
b = 55 + random.randrange(200)
self.shape.fill_color = sf.Color(r, g, b, 50)
self.shape.outline_color = sf.Color(r, g, b, 200)
self.shape.outline_thickness = 1
self.position = position
# segmentation fault (core dumped)
def draw(self, target, states):
self.shape.position = self.position - self.shape.radius
target.draw(self.shape, states)
# works fine
def draw_this(self, target):
self.shape.position = self.position - self.shape.radius
target.draw(self.shape)
class Test(object):
def __init__(self):
self.window = sf.RenderWindow(sf.VideoMode(width, height), "Render Test")
self.window.vertical_synchronization = False
self.entities = []
def run(self):
for i in range(20):
self.entities.append(Entity(sf.Vector2(
random.randrange(width),
random.randrange(height))))
while self.window.is_open:
for event in self.window.events:
if (type(event) is sf.CloseEvent):
self.window.close()
self.render()
def render(self):
self.window.clear()
for e in self.entities:
self.window.draw(e)
# e.draw_this(self.window)
self.window.display()
if __name__ == "__main__":
test = Test()
test.run()