Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SOLVED: I get segmentation fault when inheriting Drawable and trying to draw  (Read 5987 times)

0 Members and 1 Guest are viewing this topic.

warbaque

  • Newbie
  • *
  • Posts: 18
    • View Profile
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()
 
« Last Edit: February 24, 2014, 11:45:50 pm by warbaque »