Bug fix (make shure a font object isn't destroyed as long as the string
is using it) and code clean up in sf.String git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1043 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
06b5299c2b
commit
26fd1b89e4
@ -30,8 +30,6 @@
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
extern PyTypeObject PySfFontType;
|
||||
|
||||
@ -39,6 +37,7 @@ extern PyTypeObject PySfFontType;
|
||||
static void
|
||||
PySfString_dealloc(PySfString *self)
|
||||
{
|
||||
Py_CLEAR(self->font);
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
@ -48,6 +47,8 @@ PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfString *self;
|
||||
self = (PySfString *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
self->font = NULL;
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
@ -64,7 +65,11 @@ PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
|
||||
return -1;
|
||||
|
||||
if (FontTmp)
|
||||
{
|
||||
Font = (FontTmp->obj);
|
||||
Py_INCREF(FontTmp);
|
||||
self->font = FontTmp;
|
||||
}
|
||||
else
|
||||
Font = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||
|
||||
@ -148,6 +153,9 @@ PySfString_SetFont(PySfString* self, PyObject *args)
|
||||
PyErr_SetString(PyExc_ValueError, "String.SetFont() Argument must be a sf.Font");
|
||||
return NULL;
|
||||
}
|
||||
Py_CLEAR(self->font);
|
||||
Py_INCREF(args);
|
||||
self->font = Font;
|
||||
self->obj->SetFont(*(Font->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@ -191,11 +199,20 @@ PySfString_GetText(PySfString* self)
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetFont(PySfString* self)
|
||||
{
|
||||
if (self->font == NULL)
|
||||
{
|
||||
PySfFont *Font = GetNewPySfFont();
|
||||
Font->obj = new sf::Font(self->obj->GetFont());
|
||||
Font->obj = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||
Font->Owner = false;
|
||||
return (PyObject *)Font;
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_INCREF(self->font);
|
||||
return (PyObject *)(self->font);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetRect(PySfString* self)
|
||||
|
@ -29,9 +29,12 @@
|
||||
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
|
||||
#include "Font.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::String *obj;
|
||||
PySfFont *font;
|
||||
} PySfString;
|
||||
|
||||
void PySfString_InitConst();
|
||||
|
Loading…
Reference in New Issue
Block a user