# FontsDemo crash

**URL:** <https://forum.juce.com/t/fontsdemo-crash/12095>\
**Category:** General JUCE discussion\
**Created:** [December 28, 2013, 8:48pm UTC](https://forum.juce.com/t/fontsdemo-crash/12095 "2013-12-28T20:48:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matty](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@matty](https://forum.juce.com/u/matty)\
**Post date:** [December 28, 2013, 8:48pm UTC](https://forum.juce.com/t/fontsdemo-crash/12095/1 "2013-12-28T20:48:28Z")

</div>

Some font files may cause the FontsDemo to hang/crash under Win7:

```
class WindowsDirectWriteTypeface : public Typeface
{
public:
    WindowsDirectWriteTypeface (const Font& font, IDWriteFontCollection* fontCollection)
...
{
...
    hr = dwFont->CreateFontFace (dwFontFace.resetAndGetPointerAddress());

    DWRITE_FONT_METRICS dwFontMetrics;
    dwFontFace->GetMetrics (&dwFontMetrics); // XXX dwFontFace might be NULL
```

The problem font is a customized version of a typeface found at http://unifraktur.sourceforge.net/. The font was edited in FontForge and displays correctly in Windows, NexusFont, and Adobe Indesign.

JUCE Version (12/28/13): SHA-1: b439a1a4a3535d60d7324f305f9ef359766564d0

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 29, 2013, 10:34am UTC](https://forum.juce.com/t/fontsdemo-crash/12095/2 "2013-12-29T10:34:51Z")

</div>

I tried installing that in Win7 and it loaded&nbsp;and displays just fine for me!

But.. although I've no idea why it'd fail on your system and not mine, I have added some checking that should handle the situation and use the old non-Directewrite typeface as a fallback - hopefully that'll work on your machine.

---

<div class="post-metadata">

**Author:** ![matty](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@matty](https://forum.juce.com/u/matty)\
**Post date:** [December 29, 2013, 6:51pm UTC](https://forum.juce.com/t/fontsdemo-crash/12095/3 "2013-12-29T18:51:00Z")

</div>

Yeah, not sure what's up.&nbsp;To be sure it was the font I posted, I uninstalled that font, and the FontsDemo ran without crashing.

Anyway, here's another point in the code where **dwFontFace** might be nullptr:

```
// juce_win32_DirectWriteTypeLayout.cpp

static float getFontHeightToEmSizeFactor (IDWriteFont* const dwFont)
{
    ComSmartPtr<IDWriteFontFace> dwFontFace;
    dwFont->CreateFontFace (dwFontFace.resetAndGetPointerAddress());
    
    DWRITE_FONT_METRICS dwFontMetrics; **dwFontFace-\>GetMetrics (&dwFontMetrics); // XXX might be null (line 169)**
```

I checked the **HRESULT** from **CreateFontFace()** and it was 0x88985000 for my problem font:

```
DWRITE_E_FILEFORMAT
0x88985000
Indicates an error in an input file such as a font file.
```

http://msdn.microsoft.com/en-us/library/windows/desktop/hh404141

JUCE version (12/29/2013): SHA-1: 1de23b2c0625a3bfdba3a9e18e14ab7034f21f76

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 31, 2013, 10:38am UTC](https://forum.juce.com/t/fontsdemo-crash/12095/4 "2013-12-31T10:38:00Z")

</div>

Bit of a mystery why Windows would spit out the font - maybe the file just got mangled on your machine somehow.

Anyway, like I said before, I already added code to check that pointer for nullness, so&nbsp;grab the latest version if you haven't already.

---

<div class="post-metadata">

**Author:** ![matty](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@matty](https://forum.juce.com/u/matty)\
**Post date:** [December 31, 2013, 11:06am UTC](https://forum.juce.com/t/fontsdemo-crash/12095/5 "2013-12-31T11:06:14Z")

</div>

I see where you made changes, but I'm suggesting that there is yet another point in the code that has the same issue:

https://github.com/julianstorer/JUCE/blob/master/modules/juce\_graphics/native/juce\_win32\_DirectWriteTypeLayout.cpp#L169

When running the JUCE FontsDemo, it now crashes at a different point in the code--the point I've indicated in your GitHub repository (latest version).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 31, 2013, 11:28am UTC](https://forum.juce.com/t/fontsdemo-crash/12095/6 "2013-12-31T11:28:35Z")

</div>

Ah, sorry -&nbsp;I was looking at line 169 of DirectWriteTypeface.cpp, which coicidentally was the (almost identical!) line that I fixed..

Ok, thanks, I've added a check there too now.

---

<div class="post-metadata">

**Author:** ![matty](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@matty](https://forum.juce.com/u/matty)\
**Post date:** [December 31, 2013, 3:48pm UTC](https://forum.juce.com/t/fontsdemo-crash/12095/7 "2013-12-31T15:48:12Z")

</div>

Thanks! The FontsDemo now runs without crashing, even with my problem font.
