Exception when start an "empty" Qt Widgets application



  • When I create, compile and start debugging a new simplest Qt Widget Application (without adding any my own code), the application rise an exception. Print like this:

    Exception at 0x76ddc54f, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in dwrite!DWriteCreateFactory
    

    If I do not open the debugger option "CDB -> Break on -> C++ Exception", the program can continue without crash. And also it can normally run in Release build mode.

    Is this a bug?

    My environment:
    QtCreator 4.0.2, base on Qt 5.7.0 (MSVC 2013, 32 bit)
    Qt5.7.0 MSVC2015 32bit
    OS: Windows7 SP1 64bit in a VirtualBox VM on Mac OSX.

    Stack trace when option break on C++ Exception enabled:

    1  RaiseException                     KERNELBASE                    0x76ddc54f 
    2  CxxThrowException                  msvcrt                        0x75e6359c 
    3  DWriteCreateFactory                dwrite                        0x6838f4b8 
    4  DWriteCreateFactory                dwrite                        0x6838dbe0 
    5  createDirectWriteFactory           qwindowsfontdatabase.cpp 106  0x65bcf05b 
    6  initDirectWrite                    qwindowsfontdatabase.cpp 625  0x65bcfb2f 
    7  QWindowsFontDatabase::createEngine qwindowsfontdatabase.cpp 1776 0x65bcdbe0 
    8  QWindowsFontDatabase::fontEngine   qwindowsfontdatabase.cpp 1153 0x65bcc61c 
    9  loadSingleEngine                   qfontdatabase.cpp        967  0x627be92a 
    10 loadEngine                         qfontdatabase.cpp        995  0x627bea73 
    11 QFontDatabase::findFont            qfontdatabase.cpp        2674 0x627bb701 
    12 QFontDatabase::load                qfontdatabase.cpp        2795 0x627bbdac 
    13 QFontPrivate::engineForScript      qfont.cpp                215  0x6278da63 
    14 QFontMetrics::height               qfontmetrics.cpp         304  0x627b4d2b 
    15 QStatusBar::reformat               qstatusbar.cpp           497  0x632217ce 
    16 QStatusBar::setSizeGripEnabled     qstatusbar.cpp           459  0x632210ac 
    17 QStatusBar::QStatusBar             qstatusbar.cpp           242  0x63220b6f 
    18 Ui_MainWindow::setupUi             ui_mainwindow.h          47   0xac3024   
    19 MainWindow::MainWindow             mainwindow.cpp           9    0xac257a   
    20 main                               main.cpp                 7    0xac243c   
    21 WinMain                            qtmain_win.cpp           123  0xac583d   
    22 invoke_main                        exe_common.inl           99   0xac3b4e   
    23 __scrt_common_main_seh             exe_common.inl           253  0xac39b0   
    24 __scrt_common_main                 exe_common.inl           296  0xac384d   
    25 WinMainCRTStartup                  exe_winmain.cpp          17   0xac3b68   
    26 BaseThreadInitThunk                kernel32                      0x75d1336a 
    27 RtlInitializeExceptionChain        ntdll32                       0x776f9902 
    28 RtlInitializeExceptionChain        ntdll32                       0x776f98d5 
    
    


  • Can you post your code?



  • @mchinand, thank you for your reply.
    I did not add any my own code, the codes are from project wizard, an "empty" Qt Widgets Application generate by QtCreator.
    The stack trace shows the problem is in Qt's font engine and Windows DirectWrite API, maybe the exception related to some kind of my system's font problem.

    codes :
    pro:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2017-09-07T14:36:24
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = aaa
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    

    main.cpp:

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    
    

    mainwindow.ui:

    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow" >
      <property name="geometry" >
       <rect>
        <x>0</x>
        <y>0</y>
        <width>400</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle" >
       <string>MainWindow</string>
      </property>
      <widget class="QMenuBar" name="menuBar" />
      <widget class="QToolBar" name="mainToolBar" />
      <widget class="QWidget" name="centralWidget" />
      <widget class="QStatusBar" name="statusBar" />
     </widget>
     <layoutDefault spacing="6" margin="11" />
     <pixmapfunction></pixmapfunction>
     <resources/>
     <connections/>
    </ui>
    
    

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    
    

    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    


  • @mchinand
    BTW, I checked my QtCreator's UI designer, the font shows like this:

    0_1504831420586_1.png

    Is this "04b_21" strange? The "SimSun" font is because my Windows default language is Simplified Chinese.

    And also, I checked my dwrite.dll version is: 6.1.7601.23688.



  • @xuguangxiao said in Exception when start an "empty" Qt Widgets application:

    It seems to be crashing with QFontDatabase::findFont on the stack so try another font and see how it goes... I don't think it should crash anyway, though.



  • @BjornW thank you for your reply.

    I've tried "Courier New" font and "Arial" font, same result.



  • I just tried making an MSVS2015 project to call DWriteCreateFactory with IDWriteFactory UUID directly, there was no exception thrown. But when I changed to call DWriteCreateFactory with UUID IDWriteFactory2, the exception appeared, and DWriteCreateFactory API returned fail. And then, I checked QtBase source codes, in the createDirectWriteFactory function in file qwindowsfontdatabase.cpp, Qt will try to call DWriteCreateFactory with IDWriteFactory2 UUID, if failed, call the API with IDWriteFactory UUID:

    static void createDirectWriteFactory(IDWriteFactory **factory)
    {
        *factory = Q_NULLPTR;
    
        static const DWriteCreateFactoryType dWriteCreateFactory = resolveDWriteCreateFactory();
        if (!dWriteCreateFactory)
            return;
    
        IUnknown *result = NULL;
    #if defined(QT_USE_DIRECTWRITE2)
        dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory2), &result);
    #endif
    
        if (result == NULL) {
            if (FAILED(dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &result))) {
                qErrnoWarning("DWriteCreateFactory failed");
                return;
            }
        }
    
        *factory = static_cast<IDWriteFactory *>(result);
    }
    
    

    My Qt was not local built from source. I just downloaded the install package. Maybe the build environments are different. This is the reason of the problem. Maybe Qt needs to improve the compiling test scripts or let some other changing for this situation.



  • @xuguangxiao Hi, I tried to also get an exception, using MSVS2015, but alas I couldn't get it, could you try this simple program:

    #include <iostream>
    #include "dwrite.h"
    #include "dwrite_2.h"
    #pragma comment(lib,"dwrite.lib")
    
    void main()
    {
        IUnknown* result = NULL;
        DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,__uuidof(IDWriteFactory2),&result);
    
        std::cout << result;
    }
    

    I saved this as test.cpp, opened a Developer Command Prompt for VS2015 and typed:

    cl/EHa test.cpp

    Then I got a test.exe file, when I tested on Win7SP1 it prints 00000000, in Windows 8 and Windows 10 it prints a number > 0. But no C++ exceptions :-(

    P.S. The DWriteCreateFactory call returns E_NOINTERFACE (0x8004002) in Windows 7, and OK in Windows 8 and 10.



  • @hskoglund Hi, I've just tried your code. Yes, there was no exception print in the console, same as you.
    But the QtCreator debug the program in a windows debugger, if you start the program by cdb, you can see the exception print, like this:

    E:\Documents\aaa>C:\WinDDK\7600.16385.0\Debuggers\cdb.exe test.exe
    
    Microsoft (R) Windows Debugger Version 6.11.0001.404 AMD64
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    CommandLine: test.exe
    Symbol search path is: *** Invalid ***
    ****************************************************************************
    * Symbol loading may be unreliable without a symbol search path.           *
    * Use .symfix to have the debugger choose a symbol path.                   *
    * After setting your symbol path, use .reload to refresh symbol locations. *
    ****************************************************************************
    Executable search path is:
    ModLoad: 00000001`3f180000 00000001`3f1c9000   image00000001`3f180000
    ModLoad: 00000000`771c0000 00000000`7736a000   ntdll.dll
    ModLoad: 00000000`770a0000 00000000`771bf000   C:\Windows\system32\kernel32.dll
    ModLoad: 000007fe`fd270000 000007fe`fd2da000   C:\Windows\system32\KERNELBASE.dl
    l
    ModLoad: 000007fe`ee7d0000 000007fe`ee94f000   C:\Windows\system32\DWrite.dll
    ModLoad: 000007fe`ff430000 000007fe`ff4cf000   C:\Windows\system32\msvcrt.dll
    ModLoad: 000007fe`fd360000 000007fe`fd43b000   C:\Windows\system32\ADVAPI32.dll
    ModLoad: 000007fe`fd340000 000007fe`fd35f000   C:\Windows\SYSTEM32\sechost.dll
    ModLoad: 000007fe`fdb90000 000007fe`fdcbd000   C:\Windows\system32\RPCRT4.dll
    ModLoad: 000007fe`ff280000 000007fe`ff2e7000   C:\Windows\system32\GDI32.dll
    ModLoad: 00000000`76fa0000 00000000`7709a000   C:\Windows\system32\USER32.dll
    ModLoad: 000007fe`ff000000 000007fe`ff00e000   C:\Windows\system32\LPK.dll
    ModLoad: 000007fe`fdf60000 000007fe`fe02a000   C:\Windows\system32\USP10.dll
    (af0.8d4): Break instruction exception - code 80000003 (first chance)
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdl
    l.dll -
    ntdll!CsrSetPriorityClass+0x40:
    00000000`77267800 cc              int     3
    0:000> g
    ModLoad: 000007fe`fe030000 000007fe`fe05e000   C:\Windows\system32\IMM32.DLL
    ModLoad: 000007fe`fe060000 000007fe`fe169000   C:\Windows\system32\MSCTF.dll
    ModLoad: 000007fe`fae70000 000007fe`fae73000   C:\Windows\system32\api-ms-win-co
    re-synch-l1-2-0.DLL
    (af0.8d4): C++ EH exception - code e06d7363 (first chance)
    (af0.8d4): C++ EH exception - code e06d7363 (first chance)
    000000000000000000000000`00030552 c3              ret
    0:000> q
    quit:
    
    E:\Documents\aaa>
    

    Thank you for your attention!



  • @xuguangxiao I also just tried same procedure with cdb.exe but still no exceptions for me :-(

    C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64>cdb test.exe
    
    Microsoft (R) Windows Debugger Version 6.3.9600.17336 AMD64
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    CommandLine: test.exe
    Symbol search path is: *** Invalid ***
    ****************************************************************************
    * Symbol loading may be unreliable without a symbol search path.           *
    * Use .symfix to have the debugger choose a symbol path.                   *
    * After setting your symbol path, use .reload to refresh symbol locations. *
    ****************************************************************************
    Executable search path is:
    ModLoad: 00000001`3f670000 00000001`3f6b6000   image00000001`3f670000
    ModLoad: 00000000`76dd0000 00000000`76f7a000   ntdll.dll
    ModLoad: 00000000`76cb0000 00000000`76dcf000   C:\Windows\system32\kernel32.dll
    ModLoad: 000007fe`fcb30000 000007fe`fcb9a000   C:\Windows\system32\KERNELBASE.dl
    l
    ModLoad: 000007fe`ef510000 000007fe`ef6a7000   C:\Windows\system32\DWrite.dll
    ModLoad: 000007fe`fd5b0000 000007fe`fd64f000   C:\Windows\system32\msvcrt.dll
    ModLoad: 000007fe`fd4d0000 000007fe`fd5ab000   C:\Windows\system32\ADVAPI32.dll
    ModLoad: 000007fe`fd490000 000007fe`fd4af000   C:\Windows\SYSTEM32\sechost.dll
    ModLoad: 000007fe`fefb0000 000007fe`ff0dd000   C:\Windows\system32\RPCRT4.dll
    ModLoad: 000007fe`feb40000 000007fe`feba7000   C:\Windows\system32\GDI32.dll
    ModLoad: 00000000`76bb0000 00000000`76caa000   C:\Windows\system32\USER32.dll
    ModLoad: 000007fe`fe950000 000007fe`fe95e000   C:\Windows\system32\LPK.dll
    ModLoad: 000007fe`fd3c0000 000007fe`fd48a000   C:\Windows\system32\USP10.dll
    (d50.d24): Break instruction exception - code 80000003 (first chance)
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdl
    l.dll -
    ntdll!CsrSetPriorityClass+0x40:
    00000000`76e77980 cc              int     3
    0:000> g
    ModLoad: 000007fe`febb0000 000007fe`febde000   C:\Windows\system32\IMM32.DLL
    ModLoad: 000007fe`fd2b0000 000007fe`fd3b9000   C:\Windows\system32\MSCTF.dll
    ModLoad: 000007fe`f6af0000 000007fe`f6af3000   C:\Windows\system32\api-ms-win-co
    re-synch-l1-2-0.DLL
    0000000000000000ntdll!ZwTerminateProcess+0xa:
    00000000`76e1bffa c3              ret
    0:000> q
    quit:
    
    C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64>
    

    It looks pretty similar, except those 2 C++ EH exception lines and that address 0x30552, a low value like that suggests an injected DLL, but probably not Defender, perhaps you are running some other Antivirus program?



  • @hskoglund, maybe the problem was caused by the windows system. I think I should ask somebody of Microsoft :-).
    Thank you again!



  • @xuguangxiao Hi, I also have this problem. I found on MSDN that minimum supported client for IDWriteFactory2 is Windows 8.1. Probably because of that, we have this exception.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.