Commit 884b7de3 authored by cutealien's avatar cutealien

Font removing still not working as it should, but at least should no longer...

Font removing still not working as it should, but at least should no longer crash when re-loading the same font and probably will re-load a font correctly now.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3600 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ad3572a1
...@@ -32,7 +32,9 @@ CGUIFont::CGUIFont(IGUIEnvironment *env, const io::path& filename) ...@@ -32,7 +32,9 @@ CGUIFont::CGUIFont(IGUIEnvironment *env, const io::path& filename)
// don't grab environment, to avoid circular references // don't grab environment, to avoid circular references
Driver = Environment->getVideoDriver(); Driver = Environment->getVideoDriver();
SpriteBank = Environment->addEmptySpriteBank(filename); SpriteBank = Environment->getSpriteBank(filename);
if (!SpriteBank) // could be default-font which has no file
SpriteBank = Environment->addEmptySpriteBank(filename);
if (SpriteBank) if (SpriteBank)
SpriteBank->grab(); SpriteBank->grab();
} }
...@@ -51,7 +53,13 @@ CGUIFont::~CGUIFont() ...@@ -51,7 +53,13 @@ CGUIFont::~CGUIFont()
Driver->drop(); Driver->drop();
if (SpriteBank) if (SpriteBank)
{
SpriteBank->drop(); SpriteBank->drop();
// TODO: spritebank still exists in gui-environment and should be removed here when it's
// reference-count is 1. Just can't do that from here at the moment.
// But spritebank would not be able to drop textures anyway because those are in texture-cache
// where they can't be removed unless materials start reference-couting 'em.
}
} }
...@@ -61,6 +69,8 @@ bool CGUIFont::load(io::IXMLReader* xml) ...@@ -61,6 +69,8 @@ bool CGUIFont::load(io::IXMLReader* xml)
if (!SpriteBank) if (!SpriteBank)
return false; return false;
SpriteBank->clear();
while (xml->read()) while (xml->read())
{ {
if (io::EXN_ELEMENT == xml->getNodeType()) if (io::EXN_ELEMENT == xml->getNodeType())
...@@ -191,6 +201,9 @@ bool CGUIFont::load(io::IXMLReader* xml) ...@@ -191,6 +201,9 @@ bool CGUIFont::load(io::IXMLReader* xml)
void CGUIFont::setMaxHeight() void CGUIFont::setMaxHeight()
{ {
if ( !SpriteBank )
return;
MaxHeight = 0; MaxHeight = 0;
s32 t; s32 t;
...@@ -231,7 +244,7 @@ bool CGUIFont::load(const io::path& filename) ...@@ -231,7 +244,7 @@ bool CGUIFont::load(const io::path& filename)
//! load & prepare font from ITexture //! load & prepare font from ITexture
bool CGUIFont::loadTexture(video::IImage* image, const io::path& name) bool CGUIFont::loadTexture(video::IImage* image, const io::path& name)
{ {
if (!image) if (!image || !SpriteBank)
return false; return false;
s32 lowerRightPositions = 0; s32 lowerRightPositions = 0;
...@@ -293,6 +306,9 @@ bool CGUIFont::loadTexture(video::IImage* image, const io::path& name) ...@@ -293,6 +306,9 @@ bool CGUIFont::loadTexture(video::IImage* image, const io::path& name)
void CGUIFont::readPositions(video::IImage* image, s32& lowerRightPositions) void CGUIFont::readPositions(video::IImage* image, s32& lowerRightPositions)
{ {
if (!SpriteBank )
return;
const core::dimension2d<u32> size = image->getDimension(); const core::dimension2d<u32> size = image->getDimension();
video::SColor colorTopLeft = image->getPixel(0,0); video::SColor colorTopLeft = image->getPixel(0,0);
...@@ -467,7 +483,7 @@ void CGUIFont::draw(const core::stringw& text, const core::rect<s32>& position, ...@@ -467,7 +483,7 @@ void CGUIFont::draw(const core::stringw& text, const core::rect<s32>& position,
bool hcenter, bool vcenter, const core::rect<s32>* clip bool hcenter, bool vcenter, const core::rect<s32>* clip
) )
{ {
if (!Driver) if (!Driver || !SpriteBank)
return; return;
core::dimension2d<s32> textDimension; // NOTE: don't make this u32 or the >> later on can fail when the dimension width is < position width core::dimension2d<s32> textDimension; // NOTE: don't make this u32 or the >> later on can fail when the dimension width is < position width
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment