Fixed crash on exit with Qt 5.15.

This commit is contained in:
Leonardo Zide 2020-07-11 09:17:43 -07:00
parent 6f7dc6f1bb
commit 7ca69e37b7
5 changed files with 23 additions and 40 deletions

View file

@ -6,7 +6,7 @@
lcStringCache gStringCache;
lcStringCache::lcStringCache()
: mTexture(nullptr), mRefCount(0)
: mTexture(nullptr)
{
}
@ -15,27 +15,17 @@ lcStringCache::~lcStringCache()
delete mTexture;
}
void lcStringCache::AddRef(lcContext* Context)
void lcStringCache::Initialize(lcContext* Context)
{
Q_UNUSED(Context);
mRefCount++;
if (mRefCount == 1)
mTexture = new lcTexture();
mTexture = new lcTexture();
}
void lcStringCache::Release(lcContext* Context)
void lcStringCache::Reset()
{
mRefCount--;
if (mRefCount == 0)
{
Context->UnbindTexture2D(mTexture->mTexture); // todo: unbind from all contexts
delete mTexture;
mTexture = nullptr;
}
delete mTexture;
mTexture = nullptr;
}
void lcStringCache::CacheStrings(const QStringList& Strings)

View file

@ -11,8 +11,8 @@ public:
lcStringCache();
~lcStringCache();
void AddRef(lcContext* Context);
void Release(lcContext* Context);
void Initialize(lcContext* Context);
void Reset();
void CacheStrings(const QStringList& Strings);
void GetStringDimensions(int* cx, int* cy, const QString& String) const;
@ -20,7 +20,6 @@ public:
protected:
lcTexture* mTexture;
int mRefCount;
std::map<QString, lcStringCacheEntry> mStrings;
};

View file

@ -93,16 +93,13 @@ TexFont gTexFont;
TexFont::TexFont()
{
mRefCount = 0;
mTexture = 0;
memset(&mGlyphs, 0, sizeof(mGlyphs));
}
bool TexFont::Load(lcContext* Context)
bool TexFont::Initialize(lcContext* Context)
{
mRefCount++;
if (mRefCount != 1)
if (mTexture)
return true;
mFontHeight = 16;
@ -151,14 +148,9 @@ bool TexFont::Load(lcContext* Context)
return true;
}
void TexFont::Release()
void TexFont::Reset()
{
mRefCount--;
if (mRefCount == 0)
{
glDeleteTextures(1, &mTexture);
mTexture = 0;
}
mTexture = 0;
}
void TexFont::GetStringDimensions(int* cx, int* cy, const char* Text) const

View file

@ -15,8 +15,8 @@ public:
return mTexture;
}
bool Load(lcContext* Context);
void Release();
bool Initialize(lcContext* Context);
void Reset();
void PrintText(lcContext* Context, float Left, float Top, float Z, const char* Text) const;
void GetTriangles(const lcMatrix44& Transform, const char* Text, float* Buffer) const;
@ -34,7 +34,6 @@ protected:
int mTextureWidth;
int mTextureHeight;
int mFontHeight;
int mRefCount;
};
extern TexFont gTexFont;

View file

@ -96,11 +96,12 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
widget->MakeCurrent();
// TODO: Find a better place for the grid texture and font
gStringCache.AddRef(widget->mContext);
gTexFont.Load(widget->mContext);
if (gWidgetList.isEmpty())
{
// TODO: Find a better place for the grid texture and font
gStringCache.Initialize(widget->mContext);
gTexFont.Initialize(widget->mContext);
lcInitializeGLExtensions(context());
lcContext::CreateResources();
View::CreateResources(widget->mContext);
@ -115,6 +116,7 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
gPlaceholderMesh = new lcMesh;
gPlaceholderMesh->CreateBox();
}
gWidgetList.append(this);
widget->OnInitialUpdate();
@ -133,11 +135,12 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
lcQGLWidget::~lcQGLWidget()
{
gWidgetList.removeOne(this);
gStringCache.Release(widget->mContext);
gTexFont.Release();
makeCurrent();
if (gWidgetList.isEmpty())
{
gStringCache.Reset();
gTexFont.Reset();
lcGetPiecesLibrary()->ReleaseBuffers(widget->mContext);
View::DestroyResources(widget->mContext);
lcContext::DestroyResources();