FontsDemo crash

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

I tried installing that in Win7 and it loaded 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.

Yeah, not sure what's up. 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

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 grab the latest version if you haven't already.

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).

Ah, sorry - 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.

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