[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] gsoc-2022-chariri-2 b9f374b 21/30: * src/ftinspect/eng
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] gsoc-2022-chariri-2 b9f374b 21/30: * src/ftinspect/engine/engine.cpp: Fix crash on changing glyph index after |
Date: |
Mon, 11 Jul 2022 07:17:40 -0400 (EDT) |
branch: gsoc-2022-chariri-2
commit b9f374b7b87b2bda8c28a74ff1e8413125c309b6
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>
* src/ftinspect/engine/engine.cpp: Fix crash on changing glyph index after
changing size quickly.
When changing glyph index, the glyph name will be request by calling
`Engine::glyphName`, which uses the cached `ftSize_`. However, `ftSize_`
which
is set by `FTC_Manager_LookupSize`, is not guaranteed to survive after other
`FTC_ImageCache_LookupScaler` calls (called when the size changes).
When one changes the size quickly (especially by Shift+MouseWheel), the
object
the old `ftSize_` points to is actually freed by `FTC_Manager_LookupSize`
because the element count reachs the limit in the internal MRU caches.
Therefore the `ftSize_` becomes a dangling pointer, causing crash when
navigating to other glyphs.
This bug was not so apparent before because one couldn't change the size so
quickly, so memory allocating were maybe less frequent, and the dangling
pointer still holds valid data. But more intense test still can reveal this.
The solution here is simple, just lookup `ftSize_` again before fetching the
glyph name.
---
src/ftinspect/engine/engine.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/ftinspect/engine/engine.cpp b/src/ftinspect/engine/engine.cpp
index 4d0f8c2..c2e0a5d 100644
--- a/src/ftinspect/engine/engine.cpp
+++ b/src/ftinspect/engine/engine.cpp
@@ -339,6 +339,9 @@ Engine::glyphName(int index)
if (index < 0)
throw std::runtime_error("Invalid glyph index");
+ if (!FTC_Manager_LookupSize(cacheManager_, &scaler_, &ftSize_))
+ return name;
+
if (ftSize_ && FT_HAS_GLYPH_NAMES(ftSize_->face))
{
char buffer[256];
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] gsoc-2022-chariri-2 b9f374b 21/30: * src/ftinspect/engine/engine.cpp: Fix crash on changing glyph index after,
Werner Lemberg <=