# Font::findFonts() crash

**URL:** <https://forum.juce.com/t/font-findfonts-crash/53478>\
**Category:** Windows\
**Created:** [October 23, 2022, 6:04pm UTC](https://forum.juce.com/t/font-findfonts-crash/53478 "2022-10-23T18:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DicklessGreat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dicklessgreat/32/6829_2.png) [@DicklessGreat](https://forum.juce.com/u/DicklessGreat)\
**Post date:** [October 23, 2022, 6:04pm UTC](https://forum.juce.com/t/font-findfonts-crash/53478/1 "2022-10-23T18:04:11Z")

</div>

Seems like [same issue](https://forum.juce.com/t/fontsdemo-crash/12095), but it still happens.  
My app and FontsDemo crash on my machine.  
Maybe it happens only for my machine(mysterious enough, Windows sometimes badly treat font data), but those who use Font::findFonts() also suffer this problem, because it can be happen in the end-user machine.

What happened:  
`dwFont` [in Font::findAllTypefaceStyles()](https://github.com/juce-framework/JUCE/blob/965d0ca4be178c4a0000b116d460e15c30311992/modules/juce_graphics/native/juce_win32_Fonts.cpp#L258) is `nullptr` although the program expects not to be. So read access violation happens at calling `GetSimulations()`

```auto
// Ignore any algorithmically generated bold and oblique styles..
if (dwFont->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE)
     results.addIfNotAlreadyThere (getFontFaceName (dwFont));

```

My suggestion is, how about adding null check?

```auto
// Ignore any algorithmically generated bold and oblique styles..
if (dwFont != nullptr)
    if (dwFont->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE)
         results.addIfNotAlreadyThere (getFontFaceName (dwFont));

```

I don’t know why `dwFont` suddenly becomes nullptr, but by adding null check, it works fine anyway.  
(by the way, `family` was “Cascadia Code”)

---

<div class="post-metadata">

**Author:** ![DicklessGreat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dicklessgreat/32/6829_2.png) [@DicklessGreat](https://forum.juce.com/u/DicklessGreat)\
**Post date:** [October 24, 2022, 1:25am UTC](https://forum.juce.com/t/font-findfonts-crash/53478/2 "2022-10-24T01:25:41Z")

</div>

Additional information.  
According to my debugger, `fontFamily->GetFont(...)` from [Font::findAllTypefaceStyles()](https://github.com/juce-framework/JUCE/blob/965d0ca4be178c4a0000b116d460e15c30311992/modules/juce_graphics/native/juce_win32_Fonts.cpp#L255) returns

```auto
DWRITE_E_FILEACCESS
0x88985004
A font file exists but could not be opened due to access denied, sharing violation, or similar error.

```

when it crashes.  
I don’t know why this error happens, but proper error handling would be

```auto
if (SUCCEEDED(hr))
   if (dwFont->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE)
      results.addIfNotAlreadyThere (getFontFaceName (dwFont));

```

---

<div class="post-metadata">

**Author:** ![anon48770766](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon48770766](https://forum.juce.com/u/anon48770766)\
**Post date:** [October 24, 2022, 10:39am UTC](https://forum.juce.com/t/font-findfonts-crash/53478/3 "2022-10-24T10:39:39Z")

</div>

Which target platform? On iOS, if you don’t have file permissions (sandbox), you will trigger a crash any time file access is performed outside of the currently allowable tree…

---

<div class="post-metadata">

**Author:** ![DicklessGreat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dicklessgreat/32/6829_2.png) [@DicklessGreat](https://forum.juce.com/u/DicklessGreat)\
**Post date:** [October 24, 2022, 11:48am UTC](https://forum.juce.com/t/font-findfonts-crash/53478/4 "2022-10-24T11:48:11Z")

</div>

Hi, as linked issue and subcategory mentioned, Windows only.  
Forgot to mention in the body sentense! thanks.
