SFML community forums
Bindings - other languages => Python => Topic started by: Wolfram on September 11, 2010, 03:27:34 pm
-
Huhu,
I tried Python with PySFML 1.6 on Windows 7 64bit with 32bit Python 2.7 but it crashes..
(In C++ i haven't any problems...)
First I tried the sample from the PySFML tutorial, this worked good.
Than I tried the samples in the SDK but it chrashed in the Worm sample when I pressed the enter/return key.
I also tried to make a simple game but it chrashes in this line:
Window.Draw( sf.String( "MenuState" , sf.Font.GetDefaultFont(), 30 ) )
Source:
from PySFML import sf
class BaseState( object ):
def Run( self, Window ):
return None
class MenuState( BaseState ):
def __init__( self ):
super( MenuState, self ).__init__()
def Run( self, Window ):
while True:
Event = sf.Event()
while Window.GetEvent(Event):
if Event.Type == sf.Event.Closed:
return GameState
Window.Clear()
Window.Draw( sf.String( "MenuState" , sf.Font.GetDefaultFont(), 30 ) )
Window.Display()
return None
class GameState( BaseState ):
def __init__( self ):
super( GameState, self ).__init__()
def Run( self, Window ):
while True:
Event = sf.Event()
while Window.GetEvent(Event):
if Event.Type == sf.Event.Closed:
return None
Window.Clear()
Window.Draw( sf.String( "GameState" , sf.Font.GetDefaultFont(), 30 ) )
Window.Display()
return None
class Game:
def Run( self ):
Window = sf.RenderWindow( sf.VideoMode( 800, 600, 32 ), "PySFMLTest", sf.Style.Close )
Window.SetFramerateLimit( 60 )
Next_State = MenuState
while Next_State is not None:
State = Next_State()
Next_State = State.Run( Window )
Main = Game()
Main.Run()
If I remove the Window.Draw(...) lines, it works...
Is the Python binding buggy?
-
svenstaro, can you have a look into it? Maybe you adjusted something there for the 1.6 binding.
-
It probably doesn't find the media in both cases. Can you post the error please?
-
It probably doesn't find the media in both cases. Can you post the error please?
Ehm, in my sample I don't use any media, only SFML.
It crashes in both cases without an error.
Windows displays only that python.exe doesn't work anymore.
-
Works for me. Also, you are using media since you are using a font. Can you post the error that you get when running python yourapp.py from the command line?
-
Works for me. Also, you are using media since you are using a font. Can you post the error that you get when running python yourapp.py from the command line?
Ok, but the font media is build in SFML?! So I don't use any extern media.^^
I run my sample in the python shell:
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
There aren't any errors.. i get only the message from Windows that python.exe doesn't work anymore.
-
I just tested on Windows 7 x64 just for you and it worked.
EDIT: Unless you provide more info I can't really help. Did you try making PySFML yourself with your specific version of Python?
-
:-/ for me it does not work..
I tried to build them myself, but i get an error: Unable to find vcvarsall.bat
(I have VC2010 Express.)
(I don't have MinGW and I don't really know which package I need to install to use MinGW.)
Did you use also Python 2.7 on your Windows? Otherwise I'll try Python 3.. :-/
-
I used Python 2.7 and I also tried it in my virtual machine. You could updating your drivers or try it under another OS.
-
Hmpf, I tried Python 3.12 but it also crashes :-/
My drivers are up to date.
SFML with C++ works perfectly..
:-/
Maybe I try later to install MinGW and compile PySFML.
-
Please try the following:
while True:
Event = sf.Event()
while Window.GetEvent(Event):
if Event.Type == sf.Event.Closed:
return GameState
Window.Clear()
string = sf.String( "MenuState", sf.Font.GetDefaultFont(), 30 )
Window.Draw( string )
Window.Display()
I somehow think it's a reference counting problem maybe. What Wolfram forgot to say is that when he creates the sf.String object outside the while loop, everything works perfectly, so a media problem can be safely ruled out.
-
This works:
def Run( self, Window ):
string = sf.String( "MenuState", sf.Font.GetDefaultFont(), 30 )
while True:
Event = sf.Event()
while Window.GetEvent(Event):
if Event.Type == sf.Event.Closed:
return GameState
Window.Clear()
Window.Draw( string )
Window.Display()
return None
BUT, it crashes after I press Close o.O although I don't have a Window.Draw() in the GameState class.
-
And when you drop the "Window.Draw( string )" call, everything works?
-
Nope, it also crashes when I change the state. :-/
-
I can confirm that, I'll try to get more information. Python2.7 & SFML 1.6 on Win7 - 64 Bit
-
I rebuilt the sf.pyd using mingw32-gcc-4.5.0 . Did not changed anything in the sources or whatever.
Now the error does not happen.
Download it here :
Built with Python 2.7
http://www.apeironstudios.com/sf-mingw32-4.5.0-python-2.7.zip
Built with Python 3.1.2
http://www.apeironstudios.com/sf-mingw32-4.5.0-python-3.1.2.zip
Greets,
Spellbreaker
-
I am getting exactly the same errors as posted here. I'm running vista32 and python 2.7 32bit. I've tried the precompiled binaries and compiling them myself with MinGW 4.4.1 with the same results.
Whenever python tries to dispose of a sf window it will immediately crash the interpreter without an error.
from PySFML import sf
import gc
win = sf.Window()
del win # Nothing
gc.collect() # Crash
I can run the worms example but it crashes past the menu selection.
I don't know if it's related but I also get errors using some of the image functions. Specifically, sf.Image.Copy() and sf.Image.Create() will both produce this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: ..\Python\getargs.c:1424: bad argument to internal function
-
Okay I tried compiling with MinGW 4.5 and I don't get the crash errors anymore but I do still get the one error from the image functions.
-
I can confirm there is a problem.
In the worms demo, it crashes after selecting a difficulty. "Python.exe has stopped working."
It would appear to crash after running this line twice:
self['arena_rect'] = sf.Shape.Rectangle(self.arena_left, self.arena_top, self.arena_right, self.arena_bottom, sf.Color.Black)
I found that by putting prints in places closer and closer to the crash point.
def update_arena_rect(self):
print "before"
self['arena_rect'] = sf.Shape.Rectangle(self.arena_left, self.arena_top, self.arena_right, self.arena_bottom, sf.Color.Black)
print "after"
it prints "Before After Before" and then crashes.
I'm using python 2.6.6
I've tried this with Win7 32Bit and Win7 64Bit. It works, however, on WinXP 32Bit.