Solved App crashes after close and window destruction [MSVC2017 x86]
-
I'm using Qt 5.13.0. Can somebody help to find what cause next error. For me it looks like use after free but what tools I can use to find problem in code.
Maybe next bug is related to the problem but I haven't any ideas how to fix it: https://bugreports.qt.io/browse/QTBUG-39227
Stack trace:
qwindowsd.dll!QScopedPointer<QWindowsContextPrivate,QScopedPointerDeleter<QWindowsContextPrivate> >::operator->() Line 118 C++ qwindowsd.dll!QWindowsContext::windowUnderMouse() Line 686 C++ qwindowsd.dll!QWindowsWindow::destroyWindow() Line 1284 C++ qwindowsd.dll!QWindowsWindow::~QWindowsWindow() Line 1235 C++ [External Code] Qt5Guid.dll!QWindowPrivate::destroy() Line 1920 C++ Qt5Guid.dll!QWindow::destroy() Line 1870 C++ Qt5Widgetsd.dll!QWidgetPrivate::deleteTLSysExtra() Line 1903 C++ Qt5Widgetsd.dll!QWidget::destroy(bool destroyWindow, bool destroySubWindows) Line 12497 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1717 C++ Qt5Widgetsd.dll!QFrame::~QFrame() Line 264 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QComboBox::~QComboBox() Line 1420 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QGroupBox::~QGroupBox() Line 203 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ arm_auto_1.0.4.exe!AbstractSettingsWidget::~AbstractSettingsWidget() Line 12 C++ arm_auto_1.0.4.exe!WeightProcessor::~WeightProcessor() Line 24 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QFrame::~QFrame() Line 264 C++ Qt5Widgetsd.dll!QStackedWidget::~QStackedWidget() Line 147 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QTabWidget::~QTabWidget() Line 373 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QFrame::~QFrame() Line 264 C++ Qt5Widgetsd.dll!QStackedWidget::~QStackedWidget() Line 147 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QTabWidget::~QTabWidget() Line 373 C++ [External Code] Qt5Cored.dll!QObjectPrivate::deleteChildren() Line 2019 C++ Qt5Widgetsd.dll!QWidget::~QWidget() Line 1710 C++ Qt5Widgetsd.dll!QDialog::~QDialog() Line 427 C++ arm_auto_1.0.4.exe!SettingsForm::~SettingsForm() Line 86 C++ [External Code] arm_auto_1.0.4.exe!MainWindow::~MainWindow() Line 5271 C++ [External Code] [Frames below may be incorrect and/or missing, no symbols loaded for ucrtbased.dll] Unknown
-
@elnee could you please show your code? where the issue actually appears...
-
@pablo-j-rogina thank you for answer. Exactly code where crash appears is on screen. In call stack there are three main points: ~MainWindow() destructor, ~SettingsForm() destructor and ~WeightProcessor() destructor. It crashes only after close. And it looks like someone trying to access window or form, that was destructured, but I'm not sure. I need a tool to find that place in code, because code base is pretty big. Also from call stack it's obvious that app crashes when dereferencing QScopedPointer with template parameter QWindowsContextPrivate.
-
@elnee It's technically where your app crashes, but you can go back in the trace to where your last own class was used. If you're using QtCreator you can simply double click on it and the correct file & position will be shown.
Should help narrowing the issue down
-
@j-hilk thank you for answer. I found more information. It crashes in
QWindowsWindow::destroyWindow()
when trying to destroy top level windowQWindowsContext::instance()
returnsnullptr
and then crash appears on 1284 line in dereferencingcontext
pointer that isnullptr
. Any ideas what can cause that kind of behavior? WhyQWindowsContext::instance()
returnsnullptr
. How can I address an issue? -
@elnee said in App crashes after close and window destruction [MSVC2017 x86]:
~SettingsForm() destructor and ~WeightProcessor() destructor
I was asking for your actual code since sometimes it's easier to spot that a Qt object is not a children of some other Qt children and you're losing benefit of the automatic destroy feature of Qt, just to mention one case.
-
Thank you all for answers. I found the main cause of problem.
MainWindow
in that application is Singleton, so it destroys afterQApplication
destroyed. Yeah, it's a legacy code. So I just added post-routine toQApplication
viaqAddPostRoutine()
to ensure thatMainWindow
is destroyed beforeQApplication
.