mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
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"
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
extern PyTypeObject PySfColorType;
|
|
||||||
extern PyTypeObject PySfImageType;
|
|
||||||
extern PyTypeObject PySfDrawableType;
|
extern PyTypeObject PySfDrawableType;
|
||||||
extern PyTypeObject PySfFontType;
|
extern PyTypeObject PySfFontType;
|
||||||
|
|
||||||
@ -39,6 +37,7 @@ extern PyTypeObject PySfFontType;
|
|||||||
static void
|
static void
|
||||||
PySfString_dealloc(PySfString *self)
|
PySfString_dealloc(PySfString *self)
|
||||||
{
|
{
|
||||||
|
Py_CLEAR(self->font);
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
free_object(self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
@ -48,6 +47,8 @@ PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
{
|
{
|
||||||
PySfString *self;
|
PySfString *self;
|
||||||
self = (PySfString *)type->tp_alloc(type, 0);
|
self = (PySfString *)type->tp_alloc(type, 0);
|
||||||
|
if (self != NULL)
|
||||||
|
self->font = NULL;
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,11 @@ PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (FontTmp)
|
if (FontTmp)
|
||||||
|
{
|
||||||
Font = (FontTmp->obj);
|
Font = (FontTmp->obj);
|
||||||
|
Py_INCREF(FontTmp);
|
||||||
|
self->font = FontTmp;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Font = (sf::Font *)&(sf::Font::GetDefaultFont());
|
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");
|
PyErr_SetString(PyExc_ValueError, "String.SetFont() Argument must be a sf.Font");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_CLEAR(self->font);
|
||||||
|
Py_INCREF(args);
|
||||||
|
self->font = Font;
|
||||||
self->obj->SetFont(*(Font->obj));
|
self->obj->SetFont(*(Font->obj));
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -192,9 +200,18 @@ PySfString_GetText(PySfString* self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfString_GetFont(PySfString* self)
|
PySfString_GetFont(PySfString* self)
|
||||||
{
|
{
|
||||||
PySfFont *Font = GetNewPySfFont();
|
if (self->font == NULL)
|
||||||
Font->obj = new sf::Font(self->obj->GetFont());
|
{
|
||||||
return (PyObject *)Font;
|
PySfFont *Font = GetNewPySfFont();
|
||||||
|
Font->obj = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||||
|
Font->Owner = false;
|
||||||
|
return (PyObject *)Font;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Py_INCREF(self->font);
|
||||||
|
return (PyObject *)(self->font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -29,9 +29,12 @@
|
|||||||
|
|
||||||
#include <SFML/Graphics/String.hpp>
|
#include <SFML/Graphics/String.hpp>
|
||||||
|
|
||||||
|
#include "Font.hpp"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
sf::String *obj;
|
sf::String *obj;
|
||||||
|
PySfFont *font;
|
||||||
} PySfString;
|
} PySfString;
|
||||||
|
|
||||||
void PySfString_InitConst();
|
void PySfString_InitConst();
|
||||||
|
Loading…
Reference in New Issue
Block a user