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

Author Topic: Script crashes on exit (sf.RenderWindow, sf.Texture)  (Read 10617 times)

0 Members and 1 Guest are viewing this topic.

Tljjz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Script crashes on exit (sf.RenderWindow, sf.Texture)
« on: November 02, 2013, 02:57:34 pm »
I think I've found a bug in (py)SFML or Python 3.3.
When I run this code (it looks strange, but this is what remained after removing everything that didn't cause the crash):
import sfml as sf

window = sf.RenderWindow(sf.VideoMode(640, 480), 'test')

texture = sf.Texture.from_file('map.png')

window.close()
print('test')
the whole script executes, prints 'test' and then Windows shows a window saying that python.exe has stopped working. However, it doesn't crash in the IDLE python shell, only when I run the script directly.

Deleting the texture before the window is closed fixes everything:
import sfml as sf

window = sf.RenderWindow(sf.VideoMode(640, 480), 'test')

texture = sf.Texture.from_file('map.png')

del texture

window.close()
Looks like the crash is caused by the texture not being deleted before the window is closed.  :o

And this code:
import sfml as sf

window = sf.RenderWindow(sf.VideoMode(640, 480), 'test')

texture = sf.Texture.from_file('map.png')

window.close()
print('test1')
del texture
print('test2')
prints 'test1' and crashes like the first snippet, but unlike the first one it doesn't run fine in IDLE (it enters an infinite loop after print('test1')).

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Script crashes on exit (sf.RenderWindow, sf.Texture)
« Reply #1 on: November 03, 2013, 05:24:56 pm »
I can't reproduce this bug with the development version using Python 3.3 & SFML 2.1 on Linux. What pySFML version do you use ? Note that I rewrote the (de)allocation mechanism (19c077c) for pySFML 1.4 thus maybe it's fixed now.

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

Tljjz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Script crashes on exit (sf.RenderWindow, sf.Texture)
« Reply #2 on: November 03, 2013, 06:48:22 pm »
I use pySFML 1.3.
I hope a fixed version will be possible to download from the website soon, because I noticed that some of the examples also crash on exit.

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: Script crashes on exit (sf.RenderWindow, sf.Texture)
« Reply #3 on: November 03, 2013, 10:31:50 pm »
I just tried your scripts on Windows 7 x64 (fresh install), using Python3.3 and the available installer on python-sfml.org and they run well, no errors. :/

I can't help you unless you tell me more about how to reproduce this bug.
Interested in using SFML with Python ? Try out its Python binding!

Tljjz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Script crashes on exit (sf.RenderWindow, sf.Texture)
« Reply #4 on: November 04, 2013, 07:57:59 pm »
I tried reinstalling pySFML 1.3 before and nothing changed. Also, maybe the issue happens only on Windows 7 32-bit?

But today I ran the script and it closed correctly, so I ran it a few more times and now it again crashes every time.  ???
Maybe it's just some crazy Windows magic on my computer.  :-X

The crash looks like this:
The script runs correctly until the window.close() line and then pauses (no errors or exceptions) and after a few seconds Windows shows the window saying that python.exe has stopped working (but the python console window isn't frozen, I can drag or resize it and the cursor is blinking).

The examples pong, shader and spacial_music also crash on exit, but pong crashes only when exiting during the game, never on the screen saying 'Press space to start the game'.

Looks like there's something wrong with window.close(), because the crash happens when the line window.close() is executed (in the examples or in my scripts) and never when I close the the script by the python console window.
Maybe it does something wrong with other resources, because
import sfml as sf
window = sf.RenderWindow(sf.VideoMode(640, 480), 'test')
window.close()
doesn't crash.

sevdev

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Script crashes on exit (sf.RenderWindow, sf.Texture)
« Reply #5 on: April 28, 2015, 08:27:20 pm »
Windows 7 64bit
python-3.3.5.amd64
pySFML-1.3.0.win64-py3.3
PyCharm Community Edition 4.0.6

import sfml as sf

class Window(sf.RenderWindow):

    def __init__(self):
        super().__init__(sf.VideoMode(400, 300),'GAME')

if __name__ == '__main__':
    w = Window()
    sf.sleep(sf.seconds(3))
    w.close()

 

The window appears, closes and then "Python.exe has stopped working".
Console output:
Code: [Select]
Process finished with exit code -1073741819 (0xC0000005)
With slightly different code:
import sfml as sf

class Window(sf.RenderWindow):

    def load_config(self):
        self.title = 'GAME'

    def __init__(self):
        self.load_config()
        super().__init__(sf.VideoMode(400, 300), 'GAME')


if __name__ == '__main__':
    w = Window()
    sf.sleep(sf.seconds(3))
    w.close()
 
The window does not show. Instantly Python.exe crach, same message and output as for previous code.

This works normal:
import sfml as sf

if __name__ == '__main__':
    window = sf.RenderWindow(sf.VideoMode(88,88), 'yy')
    sf.sleep(sf.seconds(5))
    window.close()
 

 

anything