From 47113a1f368a10ccafc41582b0f586c5c2277d36 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 2 Jul 2015 10:18:08 +0200 Subject: DirectWrite: Fix crash when loading QRawFont from data In Qt 4, we would create and destroy the DirectWrite factory for each time we load the font data from a QRawFont. This factory would then be passed to the font engine ctor. However, in Qt 5, some things have been refactored, and the font engine will now try to use the factory stored in the sharedFontData(). This would cause dereferencing a null pointer because we didn't initialize the data before constructing the font engine. [ChangeLog][Windows][Text] Fixed crash in DirectWrite engine when constructing a QRawFont from raw font data. Task-number: QTBUG-46963 Change-Id: I4813c7f818c9df5707c27f5b6ce507649d902270 Reviewed-by: Konstantin Ritt --- .../platforms/windows/qwindowsfontdatabase.cpp | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index a544b9d81e..1c5b114efd 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -1169,23 +1169,19 @@ QT_WARNING_POP CustomFontFileLoader fontFileLoader; fontFileLoader.addKey(this, fontData); - IDWriteFactory *factory = 0; - HRESULT hres = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, - __uuidof(IDWriteFactory), - reinterpret_cast(&factory)); - if (FAILED(hres)) { - qErrnoWarning(hres, "%s: DWriteCreateFactory failed", __FUNCTION__); + QSharedPointer fontEngineData = sharedFontData(); + if (!initDirectWrite(fontEngineData.data())) return 0; - } IDWriteFontFile *fontFile = 0; void *key = this; - hres = factory->CreateCustomFontFileReference(&key, sizeof(void *), - fontFileLoader.loader(), &fontFile); + HRESULT hres = fontEngineData->directWriteFactory->CreateCustomFontFileReference(&key, + sizeof(void *), + fontFileLoader.loader(), + &fontFile); if (FAILED(hres)) { qErrnoWarning(hres, "%s: CreateCustomFontFileReference failed", __FUNCTION__); - factory->Release(); return 0; } @@ -1196,30 +1192,31 @@ QT_WARNING_POP fontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, &numberOfFaces); if (!isSupportedFontType) { fontFile->Release(); - factory->Release(); return 0; } IDWriteFontFace *directWriteFontFace = 0; - hres = factory->CreateFontFace(fontFaceType, 1, &fontFile, 0, DWRITE_FONT_SIMULATIONS_NONE, - &directWriteFontFace); + hres = fontEngineData->directWriteFactory->CreateFontFace(fontFaceType, + 1, + &fontFile, + 0, + DWRITE_FONT_SIMULATIONS_NONE, + &directWriteFontFace); if (FAILED(hres)) { qErrnoWarning(hres, "%s: CreateFontFace failed", __FUNCTION__); fontFile->Release(); - factory->Release(); return 0; } fontFile->Release(); fontEngine = new QWindowsFontEngineDirectWrite(directWriteFontFace, pixelSize, - sharedFontData()); + fontEngineData); // Get font family from font data fontEngine->fontDef.family = font.familyName(); directWriteFontFace->Release(); - factory->Release(); } #endif -- cgit v1.2.3