From 870d049bc884fec58755c5dea7b863472116bef6 Mon Sep 17 00:00:00 2001 From: remi-k Date: Mon, 2 Mar 2009 19:00:41 +0000 Subject: [PATCH] Bug fixed in sf.String Code clean up git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1037 4e206d99-4929-0410-ac5d-dfc041789085 --- python/samples/worm.py | 11 +++-------- python/src/Font.cpp | 4 ++-- python/src/SoundStream.cpp | 18 ++++++++++++++---- python/src/String.cpp | 3 +++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/python/samples/worm.py b/python/samples/worm.py index 2039f315b..685ff01f4 100644 --- a/python/samples/worm.py +++ b/python/samples/worm.py @@ -234,14 +234,9 @@ class Main: while self.win.GetEvent(event): # Event Handler if event.Type == sf.Event.Closed: self.win.Close() - elif event.Type == sf.Event.KeyPressed: - for key in self.keys: - if event.Key.Code == key: - self.keys[key](True) - elif event.Type == sf.Event.KeyReleased: - for key in self.keys: - if event.Key.Code == key: - self.keys[key](False) + elif event.Type == sf.Event.KeyPressed or event.Type == sf.Event.KeyReleased: + if event.Key.Code in self.keys: + self.keys[event.Key.Code](event.Type == sf.Event.KeyPressed) self.win.Display() self.win.Clear(background_color) self.next_frame(self.win) diff --git a/python/src/Font.cpp b/python/src/Font.cpp index 1458a0bd4..b506456a1 100644 --- a/python/src/Font.cpp +++ b/python/src/Font.cpp @@ -63,7 +63,7 @@ PySfFont_LoadFromFile(PySfFont* self, PyObject *args, PyObject *kwds) int Length; bool result; std::string Encoding; - if (PyArg_ParseTupleAndKeywords(args, kwds, "s|I:Font.LoadFromFile", (char **)kwlist, &Filename, &Charsize)) + if (PyArg_ParseTuple(args, "s|I:Font.LoadFromFile", &Filename, &Charsize)) result = self->obj->LoadFromFile(Filename, Charsize); else if (PyArg_ParseTupleAndKeywords(args, kwds, "s|Iu:Font.LoadFromFile", (char **)kwlist, &Filename, &Charsize, &Charset)) { @@ -113,7 +113,7 @@ PySfFont_LoadFromMemory(PySfFont* self, PyObject *args, PyObject *kwds) int Length; bool result; std::string Encoding; - if (PyArg_ParseTupleAndKeywords(args, kwds, "s#|I:Font.LoadFromMemory", (char **)kwlist, &Data, &Size, &Charsize)) + if (PyArg_ParseTuple(args, "s#|I:Font.LoadFromMemory", &Data, &Size, &Charsize)) result = self->obj->LoadFromMemory(Data, Size, Charsize); else if (PyArg_ParseTupleAndKeywords(args, kwds, "s#|Iu:Font.LoadFromMemory", (char **)kwlist, &Data, &Size, &Charsize, &Charset)) { diff --git a/python/src/SoundStream.cpp b/python/src/SoundStream.cpp index 89b040840..65bcb43eb 100644 --- a/python/src/SoundStream.cpp +++ b/python/src/SoundStream.cpp @@ -38,19 +38,22 @@ bool CustomSoundStream::OnStart() Py_DECREF(OnStart); Py_DECREF(Result); } + if (PyErr_Occurred()) + { + PyErr_Print(); + return false; + } return result; } bool CustomSoundStream::OnGetData(Chunk& Data) { bool result = false; - if (PyData != NULL) { - Py_DECREF(PyData); - } + Py_XDECREF(PyData); + PyData = NULL; if (PyObject_HasAttrString(SoundStream, "OnGetData")) { PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData"); - Data.NbSamples = 0; PyData = PyObject_CallFunction(Function, NULL); if (PyData != NULL) { @@ -63,6 +66,13 @@ bool CustomSoundStream::OnGetData(Chunk& Data) } Py_DECREF(Function); } + if (PyErr_Occurred()) + { + PyErr_Print(); + Py_XDECREF(PyData); + PyData = NULL; + return false; + } return result; } diff --git a/python/src/String.cpp b/python/src/String.cpp index b95517393..7e4bc5c35 100644 --- a/python/src/String.cpp +++ b/python/src/String.cpp @@ -144,7 +144,10 @@ PySfString_SetFont(PySfString* self, PyObject *args) { PySfFont *Font = (PySfFont *)args; if (!PyObject_TypeCheck(Font, &PySfFontType)) + { PyErr_SetString(PyExc_ValueError, "String.SetFont() Argument must be a sf.Font"); + return NULL; + } self->obj->SetFont(*(Font->obj)); Py_RETURN_NONE; }