Skip to content

Commit 2d5dbec

Browse files
committed
Fix crash on Windows 7 when loading a custom font collection from files
1 parent fec8998 commit 2d5dbec

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

source/DWritEx.ixx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,11 @@ HRESULT CreateFontCollection(
568568
}
569569
else
570570
{
571+
IDWriteFontFileEnumerator** enumeratorAddress = &fontFileEnumerator;
572+
571573
// Pass the address of the enumerator as the unique key.
572574
IFR(factory->RegisterFontCollectionLoader(CustomFontCollectionLoader::GetInstance()));
573-
hr = factory->CreateCustomFontCollection(CustomFontCollectionLoader::GetInstance(), fontFileEnumerator, sizeof(fontFileEnumerator), OUT fontCollection);
575+
hr = factory->CreateCustomFontCollection(CustomFontCollectionLoader::GetInstance(), enumeratorAddress, sizeof(enumeratorAddress), OUT fontCollection);
574576
IFR(factory->UnregisterFontCollectionLoader(CustomFontCollectionLoader::GetInstance()));
575577
}
576578

@@ -590,10 +592,9 @@ HRESULT CreateFontCollection(
590592

591593
CustomCollectionLocalFontFileEnumerator enumerator;
592594
IFR(enumerator.Initialize(factory, fontFileNames, fontFileNamesSize));
593-
auto* enumeratorAddress = static_cast<IDWriteFontFileEnumerator*>(&enumerator);
594-
enumeratorAddress->AddRef();
595+
enumerator.AddRef();
595596

596-
return CreateFontCollection(factory, fontFamilyModel, enumeratorAddress, OUT fontCollection);
597+
return CreateFontCollection(factory, fontFamilyModel, &enumerator, OUT fontCollection);
597598
}
598599

599600

@@ -609,9 +610,9 @@ HRESULT CreateFontCollection(
609610

610611
CustomCollectionFontFileEnumerator enumerator;
611612
IFR(enumerator.Initialize(factory, fontFiles, fontFilesCount));
612-
auto* enumeratorAddress = static_cast<IDWriteFontFileEnumerator*>(&enumerator);
613+
enumerator.AddRef();
613614

614-
return CreateFontCollection(factory, fontFamilyModel, enumeratorAddress, OUT fontCollection);
615+
return CreateFontCollection(factory, fontFamilyModel, &enumerator, OUT fontCollection);
615616
}
616617

617618

0 commit comments

Comments
 (0)