diff --git a/src/osgPlugins/freetype/FreeTypeLibrary.cpp b/src/osgPlugins/freetype/FreeTypeLibrary.cpp index 216687be2..c20412913 100644 --- a/src/osgPlugins/freetype/FreeTypeLibrary.cpp +++ b/src/osgPlugins/freetype/FreeTypeLibrary.cpp @@ -26,23 +26,17 @@ FreeTypeLibrary::FreeTypeLibrary() FreeTypeLibrary::~FreeTypeLibrary() { + // need to remove the implementations from the Fonts here + // just in case the Fonts continue to have external references + // to them, otherwise they will try to point to an object thats + // definiation has been unloaded along with the unload of the FreeType + // plugin. for(FontMap::iterator itr=_fontMap.begin(); itr!=_fontMap.end(); ++itr) { - FreeTypeFont* freetypefont = itr->second.get(); - if (freetypefont->referenceCount()>1) - { - // external references must exist... - itr->second = 0; - - freetypefont->_facade->setImplementation(0); - } - else - { - // no external references exist so its safe to delete via set the ref_ptr to 0. - itr->second = 0; - } + osgText::Font* font = itr->second.get(); + font->setImplementation(0); } FT_Done_FreeType( _ftlibrary); @@ -58,7 +52,7 @@ osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int { FontMap::iterator itr = _fontMap.find(fontfile); - if (itr!=_fontMap.end()) return itr->second->_facade; + if (itr!=_fontMap.end()) return itr->second.get(); FT_Face face; /* handle to face object */ FT_Error error = FT_New_Face( _ftlibrary, fontfile.c_str(), index, &face ); @@ -76,9 +70,9 @@ osgText::Font* FreeTypeLibrary::getFont(const std::string& fontfile,unsigned int } FreeTypeFont* fontImp = new FreeTypeFont(fontfile,face); - _fontMap[fontfile]=fontImp; - osgText::Font* font = new osgText::Font(fontImp); + _fontMap[fontfile]=font; + return font; } diff --git a/src/osgPlugins/freetype/FreeTypeLibrary.h b/src/osgPlugins/freetype/FreeTypeLibrary.h index 3a2d2ddda..8c6363048 100644 --- a/src/osgPlugins/freetype/FreeTypeLibrary.h +++ b/src/osgPlugins/freetype/FreeTypeLibrary.h @@ -15,6 +15,7 @@ #define OSGTEXT_LIBRARY #include "FreeTypeFont.h" +#include class FreeTypeLibrary { @@ -34,7 +35,7 @@ protected: * library is via the singleton instance method.*/ FreeTypeLibrary(); - typedef std::map< std::string, osg::ref_ptr > FontMap; + typedef std::map< std::string, osg::ref_ptr > FontMap; FT_Library _ftlibrary; diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index cf2450d09..8ed061173 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -65,7 +65,7 @@ osgText::Font* osgText::readFontFile(const std::string& filename) std::string foundFile = findFontFile(filename); if (foundFile.empty()) return 0; - osg::Object* object = osgDB::readObjectFile(foundFile,true); + osg::Object* object = osgDB::readObjectFile(foundFile); // if the object is a font then return it. osgText::Font* font = dynamic_cast(object);