Core/Utility: Fix font crash
Happened when the atlas was resizing while updating the text drawer, the old invalid pointer was kept (now a dangling pointer). Former-commit-id: d50153f81f1f2bdd80cfdac9dcee85eb7c28c35e
This commit is contained in:
parent
4d89b7bd4d
commit
21ad09d626
|
|
@ -113,7 +113,7 @@ class NAZARA_UTILITY_API NzFont : public NzRefCounted, public NzResource, NzNonC
|
||||||
};
|
};
|
||||||
|
|
||||||
NazaraSignal(OnFontAtlasChanged, const NzFont*); //< Args: me
|
NazaraSignal(OnFontAtlasChanged, const NzFont*); //< Args: me
|
||||||
NazaraSignal(OnFontAtlasLayerChanged, const NzFont*); //< Args: me
|
NazaraSignal(OnFontAtlasLayerChanged, const NzFont*, NzAbstractImage*, NzAbstractImage*); //< Args: me, old layer, new layer
|
||||||
NazaraSignal(OnFontDestroy, const NzFont*); //< Args: me
|
NazaraSignal(OnFontDestroy, const NzFont*); //< Args: me
|
||||||
NazaraSignal(OnFontGlyphCacheCleared, const NzFont*); //< Args: me
|
NazaraSignal(OnFontGlyphCacheCleared, const NzFont*); //< Args: me
|
||||||
NazaraSignal(OnFontKerningCacheCleared, const NzFont*); //< Args: me
|
NazaraSignal(OnFontKerningCacheCleared, const NzFont*); //< Args: me
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ class NAZARA_UTILITY_API NzSimpleTextDrawer : public NzAbstractTextDrawer
|
||||||
static NzSimpleTextDrawer Draw(NzFont* font, const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
static NzSimpleTextDrawer Draw(NzFont* font, const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
|
||||||
void OnFontInvalidated(const NzFont* font);
|
void OnFontInvalidated(const NzFont* font);
|
||||||
void OnFontRelease(const NzFont* object);
|
void OnFontRelease(const NzFont* object);
|
||||||
void UpdateGlyphs() const;
|
void UpdateGlyphs() const;
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,7 @@ void NzFont::OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* o
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pour faciliter le travail des ressources qui nous écoutent
|
// Pour faciliter le travail des ressources qui nous écoutent
|
||||||
OnFontAtlasLayerChanged(this);
|
OnFontAtlasLayerChanged(this, oldLayer, newLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzFont::OnAtlasRelease(const NzAbstractAtlas* atlas)
|
void NzFont::OnAtlasRelease(const NzAbstractAtlas* atlas)
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,9 @@ void NzSimpleTextDrawer::SetFont(NzFont* font)
|
||||||
if (m_font)
|
if (m_font)
|
||||||
{
|
{
|
||||||
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
||||||
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &NzSimpleTextDrawer::OnFontAtlasLayerChanged);
|
||||||
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, &NzSimpleTextDrawer::OnFontRelease);
|
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, &NzSimpleTextDrawer::OnFontRelease);
|
||||||
m_glyphCacheClearedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
m_glyphCacheClearedSlot.Connect(m_font->OnFontGlyphCacheCleared, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -168,6 +168,27 @@ NzSimpleTextDrawer NzSimpleTextDrawer::Draw(NzFont* font, const NzString& str, u
|
||||||
return drawer;
|
return drawer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzSimpleTextDrawer::OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer)
|
||||||
|
{
|
||||||
|
NazaraUnused(font);
|
||||||
|
|
||||||
|
#ifdef NAZARA_DEBUG
|
||||||
|
if (m_font != font)
|
||||||
|
{
|
||||||
|
NazaraInternalError("Not listening to " + NzString::Pointer(font));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Update atlas layer pointer
|
||||||
|
// Note: This can happend while updating
|
||||||
|
for (Glyph& glyph : m_glyphs)
|
||||||
|
{
|
||||||
|
if (glyph.atlas == oldLayer)
|
||||||
|
glyph.atlas = newLayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NzSimpleTextDrawer::OnFontInvalidated(const NzFont* font)
|
void NzSimpleTextDrawer::OnFontInvalidated(const NzFont* font)
|
||||||
{
|
{
|
||||||
NazaraUnused(font);
|
NazaraUnused(font);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue