Merge pull request #7674 from zzmp/leak/font

Change Font to use shared_ptr instead of freeing on _exit
This commit is contained in:
Brad Hefta-Gaub 2016-04-15 10:25:09 -07:00
commit 50856b715e
4 changed files with 12 additions and 16 deletions

View file

@ -54,9 +54,6 @@ TextRenderer3D::TextRenderer3D(const char* family, float pointSize, int weight,
}
}
TextRenderer3D::~TextRenderer3D() {
}
glm::vec2 TextRenderer3D::computeExtent(const QString& str) const {
if (_font) {
return _font->computeExtent(str);

View file

@ -12,11 +12,10 @@
#ifndef hifi_TextRenderer3D_h
#define hifi_TextRenderer3D_h
#include <memory>
#include <glm/glm.hpp>
#include <QColor>
namespace gpu {
class Batch;
}
@ -34,8 +33,6 @@ public:
static TextRenderer3D* getInstance(const char* family, float pointSize = DEFAULT_POINT_SIZE,
bool bold = false, bool italic = false, EffectType effect = NO_EFFECT, int effectThickness = 1);
~TextRenderer3D();
glm::vec2 computeExtent(const QString& str) const;
float getFontSize() const; // Pixel size
@ -55,7 +52,7 @@ private:
// text color
glm::vec4 _color;
Font* _font;
std::shared_ptr<Font> _font;
};

View file

@ -47,15 +47,15 @@ struct QuadBuilder {
static QHash<QString, Font*> LOADED_FONTS;
static QHash<QString, Font::Pointer> LOADED_FONTS;
Font* Font::load(QIODevice& fontFile) {
Font* result = new Font();
result->read(fontFile);
return result;
Font::Pointer Font::load(QIODevice& fontFile) {
Pointer font = std::make_shared<Font>();
font->read(fontFile);
return font;
}
Font* Font::load(const QString& family) {
Font::Pointer Font::load(const QString& family) {
if (!LOADED_FONTS.contains(family)) {
static const QString SDFF_COURIER_PRIME_FILENAME{ ":/CourierPrime.sdff" };

View file

@ -17,6 +17,8 @@
class Font {
public:
using Pointer = std::shared_ptr<Font>;
Font();
void read(QIODevice& path);
@ -29,8 +31,8 @@ public:
const glm::vec4* color, EffectType effectType,
const glm::vec2& bound, bool layered = false);
static Font* load(QIODevice& fontFile);
static Font* load(const QString& family);
static Pointer load(QIODevice& fontFile);
static Pointer load(const QString& family);
private:
QStringList tokenizeForWrapping(const QString& str) const;