mirror of
https://github.com/leozide/leocad
synced 2025-02-07 08:45:49 +01:00
Fixed crash on exit with Qt 5.15.
This commit is contained in:
parent
6f7dc6f1bb
commit
7ca69e37b7
5 changed files with 23 additions and 40 deletions
|
@ -6,7 +6,7 @@
|
||||||
lcStringCache gStringCache;
|
lcStringCache gStringCache;
|
||||||
|
|
||||||
lcStringCache::lcStringCache()
|
lcStringCache::lcStringCache()
|
||||||
: mTexture(nullptr), mRefCount(0)
|
: mTexture(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,27 +15,17 @@ lcStringCache::~lcStringCache()
|
||||||
delete mTexture;
|
delete mTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcStringCache::AddRef(lcContext* Context)
|
void lcStringCache::Initialize(lcContext* Context)
|
||||||
{
|
{
|
||||||
Q_UNUSED(Context);
|
Q_UNUSED(Context);
|
||||||
|
|
||||||
mRefCount++;
|
mTexture = new lcTexture();
|
||||||
|
|
||||||
if (mRefCount == 1)
|
|
||||||
mTexture = new lcTexture();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcStringCache::Release(lcContext* Context)
|
void lcStringCache::Reset()
|
||||||
{
|
{
|
||||||
mRefCount--;
|
delete mTexture;
|
||||||
|
mTexture = nullptr;
|
||||||
if (mRefCount == 0)
|
|
||||||
{
|
|
||||||
Context->UnbindTexture2D(mTexture->mTexture); // todo: unbind from all contexts
|
|
||||||
|
|
||||||
delete mTexture;
|
|
||||||
mTexture = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcStringCache::CacheStrings(const QStringList& Strings)
|
void lcStringCache::CacheStrings(const QStringList& Strings)
|
||||||
|
|
|
@ -11,8 +11,8 @@ public:
|
||||||
lcStringCache();
|
lcStringCache();
|
||||||
~lcStringCache();
|
~lcStringCache();
|
||||||
|
|
||||||
void AddRef(lcContext* Context);
|
void Initialize(lcContext* Context);
|
||||||
void Release(lcContext* Context);
|
void Reset();
|
||||||
|
|
||||||
void CacheStrings(const QStringList& Strings);
|
void CacheStrings(const QStringList& Strings);
|
||||||
void GetStringDimensions(int* cx, int* cy, const QString& String) const;
|
void GetStringDimensions(int* cx, int* cy, const QString& String) const;
|
||||||
|
@ -20,7 +20,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
lcTexture* mTexture;
|
lcTexture* mTexture;
|
||||||
int mRefCount;
|
|
||||||
|
|
||||||
std::map<QString, lcStringCacheEntry> mStrings;
|
std::map<QString, lcStringCacheEntry> mStrings;
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,16 +93,13 @@ TexFont gTexFont;
|
||||||
|
|
||||||
TexFont::TexFont()
|
TexFont::TexFont()
|
||||||
{
|
{
|
||||||
mRefCount = 0;
|
|
||||||
mTexture = 0;
|
mTexture = 0;
|
||||||
memset(&mGlyphs, 0, sizeof(mGlyphs));
|
memset(&mGlyphs, 0, sizeof(mGlyphs));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TexFont::Load(lcContext* Context)
|
bool TexFont::Initialize(lcContext* Context)
|
||||||
{
|
{
|
||||||
mRefCount++;
|
if (mTexture)
|
||||||
|
|
||||||
if (mRefCount != 1)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
mFontHeight = 16;
|
mFontHeight = 16;
|
||||||
|
@ -151,14 +148,9 @@ bool TexFont::Load(lcContext* Context)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TexFont::Release()
|
void TexFont::Reset()
|
||||||
{
|
{
|
||||||
mRefCount--;
|
mTexture = 0;
|
||||||
if (mRefCount == 0)
|
|
||||||
{
|
|
||||||
glDeleteTextures(1, &mTexture);
|
|
||||||
mTexture = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TexFont::GetStringDimensions(int* cx, int* cy, const char* Text) const
|
void TexFont::GetStringDimensions(int* cx, int* cy, const char* Text) const
|
||||||
|
|
|
@ -15,8 +15,8 @@ public:
|
||||||
return mTexture;
|
return mTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Load(lcContext* Context);
|
bool Initialize(lcContext* Context);
|
||||||
void Release();
|
void Reset();
|
||||||
|
|
||||||
void PrintText(lcContext* Context, float Left, float Top, float Z, const char* Text) const;
|
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;
|
void GetTriangles(const lcMatrix44& Transform, const char* Text, float* Buffer) const;
|
||||||
|
@ -34,7 +34,6 @@ protected:
|
||||||
int mTextureWidth;
|
int mTextureWidth;
|
||||||
int mTextureHeight;
|
int mTextureHeight;
|
||||||
int mFontHeight;
|
int mFontHeight;
|
||||||
int mRefCount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TexFont gTexFont;
|
extern TexFont gTexFont;
|
||||||
|
|
|
@ -96,11 +96,12 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
|
||||||
|
|
||||||
widget->MakeCurrent();
|
widget->MakeCurrent();
|
||||||
|
|
||||||
// TODO: Find a better place for the grid texture and font
|
|
||||||
gStringCache.AddRef(widget->mContext);
|
|
||||||
gTexFont.Load(widget->mContext);
|
|
||||||
if (gWidgetList.isEmpty())
|
if (gWidgetList.isEmpty())
|
||||||
{
|
{
|
||||||
|
// TODO: Find a better place for the grid texture and font
|
||||||
|
gStringCache.Initialize(widget->mContext);
|
||||||
|
gTexFont.Initialize(widget->mContext);
|
||||||
|
|
||||||
lcInitializeGLExtensions(context());
|
lcInitializeGLExtensions(context());
|
||||||
lcContext::CreateResources();
|
lcContext::CreateResources();
|
||||||
View::CreateResources(widget->mContext);
|
View::CreateResources(widget->mContext);
|
||||||
|
@ -115,6 +116,7 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
|
||||||
gPlaceholderMesh = new lcMesh;
|
gPlaceholderMesh = new lcMesh;
|
||||||
gPlaceholderMesh->CreateBox();
|
gPlaceholderMesh->CreateBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
gWidgetList.append(this);
|
gWidgetList.append(this);
|
||||||
|
|
||||||
widget->OnInitialUpdate();
|
widget->OnInitialUpdate();
|
||||||
|
@ -133,11 +135,12 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
|
||||||
lcQGLWidget::~lcQGLWidget()
|
lcQGLWidget::~lcQGLWidget()
|
||||||
{
|
{
|
||||||
gWidgetList.removeOne(this);
|
gWidgetList.removeOne(this);
|
||||||
gStringCache.Release(widget->mContext);
|
|
||||||
gTexFont.Release();
|
|
||||||
makeCurrent();
|
|
||||||
if (gWidgetList.isEmpty())
|
if (gWidgetList.isEmpty())
|
||||||
{
|
{
|
||||||
|
gStringCache.Reset();
|
||||||
|
gTexFont.Reset();
|
||||||
|
|
||||||
lcGetPiecesLibrary()->ReleaseBuffers(widget->mContext);
|
lcGetPiecesLibrary()->ReleaseBuffers(widget->mContext);
|
||||||
View::DestroyResources(widget->mContext);
|
View::DestroyResources(widget->mContext);
|
||||||
lcContext::DestroyResources();
|
lcContext::DestroyResources();
|
||||||
|
|
Loading…
Add table
Reference in a new issue