foliojs / font-manager

A C++ module for Node.js providing access to the system font catalog.
MIT License
295 stars 100 forks source link

Crash on Windows 7 SP1 #26

Closed manu-st closed 4 years ago

manu-st commented 6 years ago

Hi,

I have a crash when using font-manager with electron 1.7.9 on Windows 7 with SP1. What I can tell is that it crashes with this callstack:

00 DWrite!DWriteCreateFactory+0x143b3
01 DWrite!DWriteCreateFactory+0x141b3
02 fontmanager!resultFromFont(struct IDWriteFont * font = 0x00000000`00383410)+0x1ad [c:\dev\node_modules\font-manager\src\fontmanagerwindows.cc @ 127]
03 fontmanager!getAvailableFonts(unsigned int64 _Count = <Value unavailable error>, void * _Ptr = <Value unavailable error>, class std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > > _First = <Value unavailable error>)+0x1cb [c:\dev\node_modules\font-manager\src\fontmanagerwindows.cc @ 191]
04 fontmanager!getAvailableFonts<0>(class Nan::FunctionCallbackInfo<v8::Value> * info = 0x000007fe`effea7a0, class v8::Local<v8::Array> * handle = <Value unavailable error>)+0x11 [c:\dev\node_modules\font-manager\src\fontmanager.cc @ 112]
05 fontmanager!Nan::imp::FunctionCallbackWrapper(class v8::FunctionCallbackInfo<v8::Value> * info = 0x00000000`001aa660)+0xb6 [c:\dev\node_modules\font-manager\node_modules\nan\nan_callbacks_12_inl.h @ 175]
06 node!v8::internal::AllocationSpaceName+0x12cf0
...

When it fails the font being processed is the following: 0x00000000`05982040 "C:\WINDOWS\FONTS\ARIAL.TTF"

and the line of the crash seems around these:

      // this method requires windows 7, so we need to cast to an IDWriteFontFace1
      IDWriteFontFace1 *face1 = static_cast<IDWriteFontFace1 *>(face);
      bool monospace = face1->IsMonospacedFont() == TRUE;

Any idea why and how I could work around this issue?

Thanks, Manu

manu-st commented 6 years ago

Look at the code and the documentation from Microsoft about IDWriteFontFace1, it said it requires the Platform Update For Windows 7 (https://msdn.microsoft.com/en-us/library/windows/desktop/hh780409(v=vs.85).aspx) which I found at: https://www.microsoft.com/en-us/download/details.aspx?id=36805.

After installing it the crash was gone.

Could the code be modified to not crash?

TanninOne commented 6 years ago

I've created a pull request that should address this. It should then work on Windows 7 prior to the platform update but the "monospace" flag will always be set to false.