* Fixed some more memory leaks reported by valgrind and msvc by reimplementing a couple of singleton pattern based classes

* Fixed a memory leak that occurred from never deleting a wxBitmap allocated in OpenGLTextGlyph

Originally committed to SVN as r2952.
This commit is contained in:
harukalover 2009-05-18 05:51:37 +00:00
parent 392fbdfa4d
commit 6f0c5e6489
6 changed files with 37 additions and 35 deletions

View File

@ -44,11 +44,6 @@
#include "utils.h"
///////////////////
// Static instance
OpenGLText* OpenGLText::instance;
///////////////
// Constructor
OpenGLText::OpenGLText() {
@ -74,9 +69,8 @@ void OpenGLText::Reset() {
////////////////
// Get instance
OpenGLText* OpenGLText::GetInstance() {
if (!instance) instance = new OpenGLText();
wxASSERT(instance);
OpenGLText& OpenGLText::GetInstance() {
static OpenGLText instance;
return instance;
}
@ -392,6 +386,14 @@ void OpenGLTextGlyph::Draw(int x,int y) {
}
////////////////////
// Glyph Destructor
OpenGLTextGlyph::~OpenGLTextGlyph() {
if (tempBmp) delete tempBmp;
tempBmp = NULL;
}
/////////////////////
// Get glyph metrics
wxBitmap *OpenGLTextGlyph::tempBmp = NULL;

View File

@ -63,6 +63,8 @@ public:
void GetMetrics();
void Draw(int x,int y);
~OpenGLTextGlyph();
};
typedef std::map<int,OpenGLTextGlyph> glyphMap;
@ -99,19 +101,19 @@ private:
wxString fontFace;
wxFont font;
static OpenGLText* instance;
glyphMap glyphs;
std::vector <OpenGLTextTexture*> textures;
OpenGLText();
~OpenGLText();
OpenGLText(OpenGLText const&);
OpenGLText& operator=(OpenGLText const&);
OpenGLTextGlyph GetGlyph(int i);
OpenGLTextGlyph CreateGlyph(int i);
void Reset();
static OpenGLText* GetInstance();
static OpenGLText& GetInstance();
void DoSetFont(wxString face,int size,bool bold,bool italics);
void DoSetColour(wxColour col,float alpha);
void DoPrint(wxString text,int x,int y);
@ -119,9 +121,9 @@ private:
void DoGetExtent(wxString text,int &w,int &h);
public:
static wxFont GetFont() { return GetInstance()->font; }
static void SetFont(wxString face=_T("Verdana"),int size=10,bool bold=true,bool italics=false) { GetInstance()->DoSetFont(face,size,bold,italics); }
static void SetColour(wxColour col,float alpha=1.0f) { GetInstance()->DoSetColour(col,alpha); }
static void Print(wxString text,int x,int y) { GetInstance()->DoPrint(text,x,y); }
static void GetExtent(wxString text,int &w,int &h) { GetInstance()->DoGetExtent(text,w,h); }
static wxFont GetFont() { return GetInstance().font; }
static void SetFont(wxString face=_T("Verdana"),int size=10,bool bold=true,bool italics=false) { GetInstance().DoSetFont(face,size,bold,italics); }
static void SetColour(wxColour col,float alpha=1.0f) { GetInstance().DoSetColour(col,alpha); }
static void Print(wxString text,int x,int y) { GetInstance().DoPrint(text,x,y); }
static void GetExtent(wxString text,int &w,int &h) { GetInstance().DoGetExtent(text,w,h); }
};

View File

@ -45,8 +45,8 @@
////////////////
// Get instance
StandardPaths *StandardPaths::GetInstance() {
if (!instance) instance = new StandardPaths();
StandardPaths &StandardPaths::GetInstance() {
static StandardPaths instance;
return instance;
}
@ -130,8 +130,3 @@ wxString StandardPaths::DoEncodePath(wxString path) {
void StandardPaths::DoSetPathValue(wxString path,wxString value) {
paths[path] = value;
}
///////////////////
// Static instance
StandardPaths *StandardPaths::instance = NULL;

View File

@ -47,19 +47,20 @@
// Standard path conversion class
class StandardPaths {
private:
static StandardPaths *instance;
static StandardPaths *GetInstance();
static StandardPaths &GetInstance();
std::map<wxString,wxString> paths;
StandardPaths();
StandardPaths(StandardPaths const&);
StandardPaths& operator=(StandardPaths const&);
wxString DoDecodePath(wxString path);
wxString DoEncodePath(wxString path);
void DoSetPathValue(wxString path,wxString value);
public:
static wxString DecodePath(wxString path) { return GetInstance()->DoDecodePath(path); }
static wxString EncodePath(wxString path) { return GetInstance()->DoEncodePath(path); }
static void SetPathValue(wxString path,wxString value) { GetInstance()->DoSetPathValue(path,value); }
static wxString DecodePath(wxString path) { return GetInstance().DoDecodePath(path); }
static wxString EncodePath(wxString path) { return GetInstance().DoEncodePath(path); }
static void SetPathValue(wxString path,wxString value) { GetInstance().DoSetPathValue(path,value); }
};

View File

@ -84,9 +84,8 @@ void ToolTipManager::Bind(wxWindow *window,wxString tooltip,wxString hotkey1,wxS
///////////////////
// Static instance
ToolTipManager *ToolTipManager::instance = NULL;
ToolTipManager *ToolTipManager::GetInstance() {
if (!instance) instance = new ToolTipManager;
ToolTipManager &ToolTipManager::GetInstance() {
static ToolTipManager instance;
return instance;
}

View File

@ -63,8 +63,11 @@ private:
// Tooltip manager singleton
class ToolTipManager {
private:
static ToolTipManager *instance;
static ToolTipManager *GetInstance();
ToolTipManager() {};
ToolTipManager(ToolTipManager const&);
ToolTipManager& operator=(ToolTipManager const&);
static ToolTipManager &GetInstance();
std::list<ToolTipBinding> tips;
@ -72,8 +75,8 @@ private:
void AddTips(wxWindow *window,wxString tooltip,wxArrayString hotkeys);
public:
static void Update() { GetInstance()->DoUpdate(); }
static void Bind(wxWindow *window,wxString tooltip,wxArrayString hotkeys) { GetInstance()->AddTips(window,tooltip,hotkeys); }
static void Update() { GetInstance().DoUpdate(); }
static void Bind(wxWindow *window,wxString tooltip,wxArrayString hotkeys) { GetInstance().AddTips(window,tooltip,hotkeys); }
static void Bind(wxWindow *window,wxString tooltip,wxString hotkey=_T(""));
static void Bind(wxWindow *window,wxString tooltip,wxString hotkey1,wxString hotkey2);
};