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

Author Topic: [Solved] Somes problems with sf.Event  (Read 17621 times)

0 Members and 3 Guests are viewing this topic.

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
[Solved] Somes problems with sf.Event
« on: May 04, 2013, 07:00:39 pm »
It's me again :D

Well, today I have fix somes of my problems and only one survive. When I launch my script (test.py : see src.zip), only one time on two the script doesn't throw a segmentation fault. After many and many test, I found the problem :

TypeError: 'sfml.window.ResizeEvent' object is not iterable

When I do (on EventManager.update() ) :

for event in window.events:
    some code....

At the beginning, the window is resize. If the first test doesn't yield an error, I can resize my window, here isn't the problem : the problem is that an event can't be a sf.ResizeEvent for the first (and only the first) test I think (I'm not sur for 100% ).

with GDB, I have this errors on the traceback (always one time on two) :

Program received signal SIGSEGV, Segmentation fault.
PyObject_GetAttrString (v=0x6d00000005750000, name=0x7ffff1d244c8 "on_resize") at Objects/object.c:819
819     Objects/object.c: Aucun fichier ou dossier de ce type.
 

You can find the source on the attachment (the most importante in this sources are the property and the updates functions only). Maybe the problem is that my guiml.Window inherite from sf.RenderWindow, I don't know... (Indeed, with a sf.RenderWindow, I don't have this problem).

Thank you and sorry for desagrements :) .

[attachment deleted by admin]
« Last Edit: November 04, 2013, 10:04:28 am by Sonkun »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #1 on: May 05, 2013, 08:01:32 pm »
Hello ;)

Which script am I suppose to run ? I guess you use Python 3.3.

I tried test.py and test2.py, both run fine and I'm able to resize the window without getting a segmentation fault.
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #2 on: May 05, 2013, 08:09:11 pm »
test2.py works fine (it don't use others modules). The problem is test.py : it yield a segmentation fault 1 test all of 2 tests, and I don't know why... And yes I use python3.3
« Last Edit: May 05, 2013, 08:14:28 pm by gaulois94 »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #3 on: May 05, 2013, 09:00:51 pm »
It works fine on my computer, with python3.3 :/ It must be the ArchLinux package script which doesn't install pySFML properly.
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #4 on: May 06, 2013, 11:23:45 pm »
Maybe. I have a little script who realize the same problem !

#!/usr/bin/python3
#-*-coding:utf-8-*-

import sfml as sf

class Window(sf.RenderWindow):
        def __init__(self, MODE, STRING):
                sf.RenderWindow.__init__(self, MODE, STRING)

window = Window(sf.VideoMode(800,600,32),"teste")
window.framerate_limit = 60
event = EventManager(window)

check = sf.CircleShape(20)
check.position = sf.Vector2()

while window.is_open:
        for event in window.events:
                pass
        window.clear()
        window.draw(check)
        window.display()

note that if you resize the window, the view is not resize correctly (see where de Circle is and where it should be)

Thank you :) .
« Last Edit: May 06, 2013, 11:36:02 pm by gaulois94 »

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #5 on: May 07, 2013, 09:55:03 am »
Thanks for reporting this issue :)

When you subclass sf.RenderWindow, its C-level constructor seem not to be called and causes a segmentation fault when the Python object is destroyed probably because it's trying to deallocate an unallocated resource (since the constructor didn't allocate it).
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #6 on: June 01, 2013, 10:00:28 pm »
Sorry for insisting, but can you fix this problem soon ?

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #7 on: June 02, 2013, 02:54:25 am »
Sorry, I tried to solve it one week ago and I just couldn't reproduce the issue... :/ So I guess I messed up somewhere, probably with git and its merge/rebase mechanism.

Can you provide a minimal code which reproduces the error (the one you provided uses EventManager which isn't implemented) ?

Thanks :)
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #8 on: June 02, 2013, 10:57:03 am »
#!/usr/bin/python3
#-*-coding:utf-8-*-

import sfml as sf

class Window(sf.RenderWindow):
    def __init__(self, MODE, STRING):
        sf.RenderWindow.__init__(self, MODE, STRING)

window = Window(sf.VideoMode(800,600,32),"teste")
window.framerate_limit = 60

check = sf.CircleShape(20)
check.position = sf.Vector2()

while window.is_open:
    for event in window.events:
        pass

    window.clear()
    window.draw(check)
    window.display()

Sorry, I created a EventManager but don't use it. Maybe is my last sfml version the problem (I used the official 2.0).

Sorry again :) .

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #9 on: June 14, 2013, 06:38:06 pm »
Again I couldn't reproduce the issue, let me fresh install.. I'll tell you tonight.
Interested in using SFML with Python ? Try out its Python binding!

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #10 on: June 19, 2013, 01:57:58 am »
Sorry it took so long... here's the workaround:

class Window2(sf.RenderWindow):
    def __init__(self, MODE, STRING):
        sf.RenderWindow.__init__(self, MODE, STRING)

window = Window2(sf.VideoMode(800,600,32),"teste")
window.framerate_limit = 60

Rename class Window to something else.

I'll fix it later.

There's also a hidden bug in your code:
for event in window.events:
     pass
 

This won't work on Python3.2 (only this version, 2.x and 3.3 do well) because you do nothing with the generator. This is a Cython bug. Add something inside the loop and it will work.
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #11 on: June 19, 2013, 12:50:09 pm »
Sorry, for me "pass" works with generator, but may it's because I use python 3.3. I tried this code :

#!/usr/bin/python3
#-*-coding:utf-8-*-

import sfml as sf

class Window2(sf.RenderWindow):
        def __init__(self, MODE, STRING):
                sf.RenderWindow.__init__(self, MODE, STRING)
window = Window2(sf.VideoMode(800,600,32),"teste")
window.framerate_limit = 60

check = sf.CircleShape(20)
check.position = sf.Vector2()

while window.is_open:
        for event in window.events:
                print("ok")

        window.clear()
        window.draw(check)
        window.display()
 

but the conclusion is the same : I have an error of segmentation....

sorry for the problem.

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Somes problems with sf.Event
« Reply #12 on: June 20, 2013, 12:21:43 am »
Weird. Renaming its name has solved everything on my computer... :/ Actually, when a Window2 object is destroyed, since it inherits from sf.Window, the sf.Window destructor is called and deletes the internal C++ object IF the class name is "Window". The original purpose of that is to separate the sf.Window and sf.RenderWindow destructor behavior, the first destroying sf::Window and the second destroying sf::RenderWindow.

I need to rework the inheritance implementation (which isn't straight forward, no documentation or official how-to). One of the remaining task before the next version (1.4) is the investigation of the usage of smart C++ pointer which might  be a solution to that issue.
Interested in using SFML with Python ? Try out its Python binding!

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #13 on: June 20, 2013, 01:08:08 pm »
Here you can find screenshots who explain the problem :
As you can see, I have many errors of segmentation. With a resize, the circle is not resized :


Thank you :) .

gaulois94

  • Sr. Member
  • ****
  • Posts: 259
    • View Profile
Re: Somes problems with sf.Event
« Reply #14 on: July 09, 2013, 01:06:11 pm »
Maybe with this code you can find the problem :
#!/usr/bin/python3
#-*-coding:utf-8-*-

import sfml as sf

class Window2(sf.RenderWindow):
        def __init__(self, MODE, STRING):
                sf.RenderWindow.__init__(self, MODE, STRING)
window = Window2(sf.VideoMode(800,600,32),"teste")
window.framerate_limit = 60

check = sf.CircleShape(20)
check.position = sf.Vector2()

while window.is_open:
        for event in window.events:
                if type(event) is sf.CloseEvent:
                        window.close()
                if type(event) is sf.ResizeEvent:
                        print(1)

        window.clear()
        window.draw(check)
        window.display()
 

I tried with the lateste sfml git version and with the official 2.0 version. I use your git repository and python3

and the error are :
1Traceback (most recent call last):
  File "./test.py", line 20, in <module>
    print(1)
AttributeError: 'str' object has no attribute 'on_resize'
 

or
1Traceback (most recent call last):
  File "./test.py", line 20, in <module>
    print(1)
SystemError: null argument to internal routine
 

Sorry for problems :) .