Environment
TeXstudio: 4.9.5 R
Qt: Qt 6 (6.x UCRT MinGW build)
OS: Windows (10/11 x64)
TeX distribution: irrelevant. Editor issue.
Expected behavior
When an open document is reloaded (either manually or automatically via external file changes), TeXstudio should clear and update the internal structure and line handles without crashing.
Actual behavior
TeXstudio crashes during document reload due to an invalid memory access / iterator error while updating structure items (LatexDocument::labelItems()).
How to reproduce:
Does not happen every time. Risky situations are when working with *.tex files from network drive and when the files are actually modified or when TeXstudio thinks they were modified due to long idle (or PC sleep) and consequent network refresh (with no actual file change).
Check the backtrace.
Backtrace file content:
(TXS-Version 4.9.5 R )
0# print_backtrace(QString const&) at D:/a/texstudio/texstudio/src/debug/debughelper.cpp:1325 [0x7ff603c4b3b6]
1# Texstudio::recoverFromCrash() at D:/a/texstudio/texstudio/src/texstudio.cpp:11664 [0x7ff603acb287]
2# _gnu_exception_handler at D:/W/B/src/mingw-w64/mingw-w64-crt/crt/crt_handler.c:217 [0x7ff603d274a1]
3# register_frame_ctor [0x7ffa12983212]
4# register_frame_ctor [0x7ffa129c796e]
5# register_frame_ctor [0x7ffa128d6396]
6# register_frame_ctor [0x7ffa129c72ad]
7# QMultiHash<QDocumentLineHandle*, ReferencePair>::const_iterator::const_iterator(QHashPrivate::iterator<QHashPrivate::MultiNode<QDocumentLineHandle*, ReferencePair> >, QHashPrivate::MultiNodeChain) at D:/a/_temp/msys64/ucrt64/include/qt6/QtCore/qhash.h:2118 [0x7ff603e9b7e2]
8# LatexDocument::someItems(QMultiHash<QDocumentLineHandle*, ReferencePair> const&) at D:/a/texstudio/texstudio/src/latexdocument.cpp:2076 [0x7ff60395ce60]
9# LatexDocument::labelItems() const at D:/a/texstudio/texstudio/src/latexdocument.cpp:2088 [0x7ff603973657]
10# LatexDocuments::removeDocs(QList) at D:/a/texstudio/texstudio/src/latexdocument.cpp:2638 [0x7ff60397434a]
11# LatexDocument::patchStructureRemoval(QDocumentLineHandle*, int, int) at D:/a/texstudio/texstudio/src/latexdocument.cpp:306 [0x7ff60397598b]
12# register_frame_ctor [0x7ff9bb6a2799]
13# void QMetaObject::activate<void, QDocumentLineHandle*, int, int>(QObject*, QMetaObject const*, int, void*, QDocumentLineHandle* const&, int const&, int const&) at D:/a/_temp/msys64/ucrt64/include/qt6/QtCore/qobjectdefs.h:319 [0x7ff6037e5d8e]
14# QDocument::setText(QString const&, bool, bool) at D:/a/texstudio/texstudio/src/qcodeedit/lib/document/qdocument.cpp:676 [0x7ff603c06401]
15# QDocument::load(QString const&, QTextCodec*, bool) at D:/a/texstudio/texstudio/src/qcodeedit/lib/document/qdocument.cpp:801 [0x7ff603c06899]
16# QEditor::load(QString const&, QTextCodec*, bool) at D:/a/texstudio/texstudio/src/qcodeedit/lib/qeditor.cpp:1579 [0x7ff603bc0eb1]
17# QEditor::reload() at D:/a/texstudio/texstudio/src/qcodeedit/lib/qeditor.cpp:1632 [0x7ff603bc1413]
18# QEditor::qt_static_metacall(QObject*, QMetaObject::Call, int, void) at D:/a/texstudio/texstudio/build/texstudio_autogen/DCN5INIVC3/moc_qeditor.cpp:903 [0x7ff603803fd3]
19# register_frame_ctor [0x7ff9bb35f09a]
20# register_frame_ctor [0x7ff9bb3604a6]
21# std::enable_if<!std::disjunction<std::is_base_of<QGenericArgument, QMetaMethodArgument> >::value, bool>::type QMetaObject::invokeMethod<void, QMetaMethodArgument>(QObject*, char const*, Qt::ConnectionType, QTemplatedMetaMethodReturnArgument, QMetaMethodArgument&&) at D:/a/_temp/msys64/ucrt64/include/qt6/QtCore/qobjectdefs.h:398 [0x7ff603bd7a2f]
22# register_frame_ctor [0x7ff9bb3a00d2]
23# register_frame_ctor [0x7ff9b98b6823]
24# register_frame_ctor [0x7ff9bb348d97]
25# register_frame_ctor [0x7ff9bb54d0fa]
26# register_frame_ctor [0x7ff9bb54df19]
27# register_frame_ctor [0x7ff9b98b6823]
28# register_frame_ctor [0x7ff9bb348837]
29# register_frame_ctor [0x7ff9bb34d57b]
30# register_frame_ctor [0x7ff9bad27411]
31# register_frame_ctor [0x7ff9bb54a359]
32# register_frame_ctor [0x7ff9bad273e8]
33# register_frame_ctor [0x7ff9bb355fe2]
34# register_frame_ctor [0x7ff9bb3533d3]
35# qMain(int, char**) at D:/a/texstudio/texstudio/src/main.cpp:242 [0x7ff6039e74a5]
36# register_frame_ctor [0x7ff603d27bf9]
37# __tmainCRTStartup at D:/W/B/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:260 [0x7ff6037e10d9]
38# WinMainCRTStartup at D:/W/B/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:98 [0x7ff6037e1435]
39# register_frame_ctor [0x7ffa1132e8d6]
40# register_frame_ctor [0x7ffa12868d9b]
Environment
TeXstudio: 4.9.5 R
Qt: Qt 6 (6.x UCRT MinGW build)
OS: Windows (10/11 x64)
TeX distribution: irrelevant. Editor issue.
Expected behavior
When an open document is reloaded (either manually or automatically via external file changes), TeXstudio should clear and update the internal structure and line handles without crashing.
Actual behavior
TeXstudio crashes during document reload due to an invalid memory access / iterator error while updating structure items (LatexDocument::labelItems()).
How to reproduce:
Does not happen every time. Risky situations are when working with *.tex files from network drive and when the files are actually modified or when TeXstudio thinks they were modified due to long idle (or PC sleep) and consequent network refresh (with no actual file change).
Check the backtrace.
Backtrace file content:
(TXS-Version 4.9.5 R )
0# print_backtrace(QString const&) at D:/a/texstudio/texstudio/src/debug/debughelper.cpp:1325 [0x7ff603c4b3b6]
1# Texstudio::recoverFromCrash() at D:/a/texstudio/texstudio/src/texstudio.cpp:11664 [0x7ff603acb287]
2# _gnu_exception_handler at D:/W/B/src/mingw-w64/mingw-w64-crt/crt/crt_handler.c:217 [0x7ff603d274a1]
3# register_frame_ctor [0x7ffa12983212]
4# register_frame_ctor [0x7ffa129c796e]
5# register_frame_ctor [0x7ffa128d6396]
6# register_frame_ctor [0x7ffa129c72ad]
7# QMultiHash<QDocumentLineHandle*, ReferencePair>::const_iterator::const_iterator(QHashPrivate::iterator<QHashPrivate::MultiNode<QDocumentLineHandle*, ReferencePair> >, QHashPrivate::MultiNodeChain) at D:/a/_temp/msys64/ucrt64/include/qt6/QtCore/qhash.h:2118 [0x7ff603e9b7e2]
8# LatexDocument::someItems(QMultiHash<QDocumentLineHandle*, ReferencePair> const&) at D:/a/texstudio/texstudio/src/latexdocument.cpp:2076 [0x7ff60395ce60]
9# LatexDocument::labelItems() const at D:/a/texstudio/texstudio/src/latexdocument.cpp:2088 [0x7ff603973657]
10# LatexDocuments::removeDocs(QList) at D:/a/texstudio/texstudio/src/latexdocument.cpp:2638 [0x7ff60397434a]
11# LatexDocument::patchStructureRemoval(QDocumentLineHandle*, int, int) at D:/a/texstudio/texstudio/src/latexdocument.cpp:306 [0x7ff60397598b]
12# register_frame_ctor [0x7ff9bb6a2799]
13# void QMetaObject::activate<void, QDocumentLineHandle*, int, int>(QObject*, QMetaObject const*, int, void*, QDocumentLineHandle* const&, int const&, int const&) at D:/a/_temp/msys64/ucrt64/include/qt6/QtCore/qobjectdefs.h:319 [0x7ff6037e5d8e]
14# QDocument::setText(QString const&, bool, bool) at D:/a/texstudio/texstudio/src/qcodeedit/lib/document/qdocument.cpp:676 [0x7ff603c06401]
15# QDocument::load(QString const&, QTextCodec*, bool) at D:/a/texstudio/texstudio/src/qcodeedit/lib/document/qdocument.cpp:801 [0x7ff603c06899]
16# QEditor::load(QString const&, QTextCodec*, bool) at D:/a/texstudio/texstudio/src/qcodeedit/lib/qeditor.cpp:1579 [0x7ff603bc0eb1]
17# QEditor::reload() at D:/a/texstudio/texstudio/src/qcodeedit/lib/qeditor.cpp:1632 [0x7ff603bc1413]
18# QEditor::qt_static_metacall(QObject*, QMetaObject::Call, int, void) at D:/a/texstudio/texstudio/build/texstudio_autogen/DCN5INIVC3/moc_qeditor.cpp:903 [0x7ff603803fd3]
19# register_frame_ctor [0x7ff9bb35f09a]
20# register_frame_ctor [0x7ff9bb3604a6]
21# std::enable_if<!std::disjunction<std::is_base_of<QGenericArgument, QMetaMethodArgument> >::value, bool>::type QMetaObject::invokeMethod<void, QMetaMethodArgument>(QObject*, char const*, Qt::ConnectionType, QTemplatedMetaMethodReturnArgument, QMetaMethodArgument&&) at D:/a/_temp/msys64/ucrt64/include/qt6/QtCore/qobjectdefs.h:398 [0x7ff603bd7a2f]
22# register_frame_ctor [0x7ff9bb3a00d2]
23# register_frame_ctor [0x7ff9b98b6823]
24# register_frame_ctor [0x7ff9bb348d97]
25# register_frame_ctor [0x7ff9bb54d0fa]
26# register_frame_ctor [0x7ff9bb54df19]
27# register_frame_ctor [0x7ff9b98b6823]
28# register_frame_ctor [0x7ff9bb348837]
29# register_frame_ctor [0x7ff9bb34d57b]
30# register_frame_ctor [0x7ff9bad27411]
31# register_frame_ctor [0x7ff9bb54a359]
32# register_frame_ctor [0x7ff9bad273e8]
33# register_frame_ctor [0x7ff9bb355fe2]
34# register_frame_ctor [0x7ff9bb3533d3]
35# qMain(int, char**) at D:/a/texstudio/texstudio/src/main.cpp:242 [0x7ff6039e74a5]
36# register_frame_ctor [0x7ff603d27bf9]
37# __tmainCRTStartup at D:/W/B/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:260 [0x7ff6037e10d9]
38# WinMainCRTStartup at D:/W/B/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:98 [0x7ff6037e1435]
39# register_frame_ctor [0x7ffa1132e8d6]
40# register_frame_ctor [0x7ffa12868d9b]