bugGNU TeXmacs - Bugs: bug #61884, Segmentation fault when closing...


You are not allowed to post comments on this tracker with your current authentication level.

bug #61884: Segmentation fault when closing windows with unsaved documents

Submitter:  Jeroen Wouters <jeronim>
Submitted:  Thu 20 Jan 2022 10:40:41 PM UTC
Category:  Qt port Priority:  7 - High
Item Group:  Error Status:  Ready For Test
Privacy:  Public Assigned to:  mgubi
Originator Name:  Open/Closed:  Open
Release:  None Release:  2.1.1
Fixed Release:  None Fixed Release: 

Jump to the original submission

Sun 06 Aug 2023 03:39:10 PM UTC, comment #11: 

I tested under MacOS.  With Qt4, the new code systematically segfaults when loading a document that opens a warning window (e.g. some newer entries in the bibliography) and then closing.
With Qt5 this still occurs sporadically, but in a non-deterministic manner.  With Qt5, I also get the following messages when closing Qt5 (after loading the document as above):

QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
QBasicTimer::start: QBasicTimer can only be used with threads started with QThread

I #ifdeffed the Mac case.

Max: any idea why we have this problem under MacOS?

Joris van der Hoeven <vdhoeven>
Group administrator
Wed 04 Jan 2023 07:50:21 PM UTC, comment #10: 

I was experiencing the bug in linux because that's what I use >99% of time. I tested that the proposed fix does not cause any obvious problem in windows, but I can't test on MacOS.

I commited the fix as rev 14500. Leaving open in case the fix raises other issues.

Philippe Joyez <pjoyez>
Group Member
Mon 02 Jan 2023 11:13:03 AM UTC, comment #9: 

comment #8:

> In ~qt_window_widget_rep (), changing "qwid->deleteLater()" to "delete qwid" is an effective fix for this bug.
> Any advice against? 

not from my side. Maybe leave there a remark on why it is so with a reference to the bug, so that we will avoid to undo it, in case some other crashes appear in other platforms. Have you tested only Windows?

Massimiliano Gubinelli <mgubi>
Group administrator
Mon 02 Jan 2023 10:40:04 AM UTC, comment #8: 

In ~qt_window_widget_rep (), changing "qwid->deleteLater()" to "delete qwid" is an effective fix for this bug.

Any advice against?

Philippe Joyez <pjoyez>
Group Member
Sun 01 Jan 2023 07:08:24 PM UTC, comment #7: 

I now have several simple patterns that crash TeXmacs with certainty or very high probability, even with debug symbols and debug switches.

The crash seems to always occur In QTMWindow.cpp on a line :
string name= ( !is_nil(tmwid) ? concrete(tmwid)->get_nickname () : "QTMWindow")
i.e. most likely when trying to figure the window's name (but failing along the way because a pointer became invalid?)

As Jeroen and I reported, the crash mostly occurs in QTMWindow::moveEvent, definitely after the window has been destroyed, which likely explains the crash.

I note that at the time of the crash, on the console I get a qt warning message as reported in https://bugreports.qt.io/browse/QTBUG-56893 and https://bugreports.qt.io/browse/QTBUG-87141, signaling an event was sent to a destroyed object (an occurence that cannot be avoided and which should be begnin according to the qt folks). This qt warning is also present when using the Appimage (that does not crash) which seems to confirm the Qt folks opinion.

The bug is still present in a qt6 build. So, fixing it is not just a matter of waiting we get to qt6 ...

Maybe the code should explictly forbid the window to receive further events, at the time it is closed?

Side remark : While investigating this, I realized that the notify_window_destroy call in QTMWindow::closeEvent is probably too early because the user may later cancel the window closing in case the buffer was not saved. Yet deleting the window name does not seem to be a serious issue in the AppImage...


Philippe Joyez <pjoyez>
Group Member
Thu 08 Dec 2022 10:36:54 AM UTC, comment #6: 

I confirm that for me too, when working with several windows and closing one of them, Texmacs crashes occasionally. Given this occurs when closing windows, it somewhat reminds me of bug #49655...

In any case, I've found a rather minimal way of triggering the bug in Debian, involving only two windows:

- in a terminal launch : texmacs a.tm b.tm  (opening new files, but same result if the files exist)

(if necessary, move the window on top (b.tm) and so that you can see the back window)

- Click in the text area of the back window ("a.tm") and type the shortcut Ctrl-W to close the window -> Segfault

For me it's fully reproducible in a build of the latest revision (at this point, 14091) in Debian Bookworm, with Qt 5.15.6. It is also reproducible if you clear the content of ~/.TeXmacs, provided you restore the preference setting "buffers in separate windows" afterwards.

However this simple procedure won't crash texmacs in case :

- texmacs is started with the --debug-qt option.
- you run the Appimages I make (that confirms what Jeroen already found). I suspect it's because they use an older Qt5 (Qt5.6 and Qt5.12, IIRC)
-texmacs is built with the --enable-debug configure option. This is pretty odd for me. And saddly, it prevents getting precise info on the crash...

If I run the code built without debugging symbols in gdb, the backtrace I get after a crash is:

#0  0x00005555557084ca in QTMWindow::moveEvent(QMoveEvent*) ()
#1  0x00007ffff77a57e3 in QWidget::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#2  0x00007ffff7762f5e in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#3  0x0000555555e4796c in QTMApplication::notify(QObject*, QEvent*) ()
#4  0x00007ffff6ab1718 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#5  0x00007ffff77bf46c in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#6  0x00007ffff77c10cb in  () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#7  0x00007ffff7762f5e in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#8  0x0000555555e4796c in QTMApplication::notify(QObject*, QEvent*) ()
#9  0x00007ffff6ab1718 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#10 0x00007ffff6f39ba7 in QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent*) ()
    at /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5

Philippe Joyez <pjoyez>
Group Member
Mon 17 Oct 2022 09:23:41 AM UTC, comment #5: 

I just tried this with the Qt4 version from the website (from the rpm for Fedora) and the Qt5 AppImage version by Philippe. I can't reproduce it in either. It may be something about my particular version of Qt.

Jeroen Wouters <jeronim>
Group Member
Thu 19 May 2022 10:00:21 AM UTC, comment #4: 

I have obtained a more informative backtrace from gdb with full debug info (attached in txt and highlighted html format).

(file #53228, file #53229)

Jeroen Wouters <jeronim>
Group Member
Thu 27 Jan 2022 10:56:26 AM UTC, comment #3: 

I get the following on the terminal:

TeXmacs] With linked TrueType support
Throwing segmentation fault
Error message:
  segmentation fault

System information:
  TeXmacs version  : 2.1
  Built by         : jeroen
  Building date    : 2022-01-27T09:48:56
  Operating system : linux-gnu
  Vendor           : pc
  Processor        : x86_64
  Crash date       : Thu 27 Jan 09:50:42 GMT 2022

Editor status:
  Root path          : [ 9 ]
  Current path       : [ 9, 0, 0 ]
  Shifted path       : [ 9, 0, 0 ]
  Physical selection : [ 9, 0, 0 ] -- [ 9, 0, 0 ]

Backtrace of C++ stack:
  texmacs.bin() [0x5e6206]
  texmacs.bin() [0x4a5137]
  texmacs.bin() [0x475650]
  /lib64/libc.so.6 : () + 0x42750
  texmacs.bin() [0x7c70e9]
  /lib64/libQt5Widgets.so.5 : QWidget::event(QEvent*) + 0xc8c
  /lib64/libQt5Widgets.so.5 : QApplicationPrivate::notify_helper(QObject*, QEvent*) + 0x83
  texmacs.bin() [0x4819d2]
  /lib64/libQt5Core.so.5 : QCoreApplication::notifyInternal2(QObject*, QEvent*) + 0x128
  /lib64/libQt5Widgets.so.5 : () + 0x20bc6a
  /lib64/libQt5Widgets.so.5 : () + 0x20da24
  /lib64/libQt5Widgets.so.5 : QApplicationPrivate::notify_helper(QObject*, QEvent*) + 0x83
  texmacs.bin() [0x4819d2]
  /lib64/libQt5Core.so.5 : QCoreApplication::notifyInternal2(QObject*, QEvent*) + 0x128
  /lib64/libQt5Gui.so.5 : QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent*) + 0x201
  /lib64/libQt5Gui.so.5 : QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 0xac
  /lib64/libQt5XcbQpa.so.5 : () + 0x6f11e
  /lib64/libglib-2.0.so.0 : g_main_context_dispatch() + 0x1a0
  /lib64/libglib-2.0.so.0 : () + 0xaa208
  /lib64/libglib-2.0.so.0 : g_main_context_iteration() + 0x33
  /lib64/libQt5Core.so.5 : QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 0x68
  /lib64/libQt5Core.so.5 : QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 0x132
  /lib64/libQt5Core.so.5 : QCoreApplication::exec() + 0x94
  texmacs.bin() [0x7d1af8]
  texmacs.bin() [0x7d1b55]
  texmacs.bin() [0x479104]
  texmacs.bin() [0x4c8f88]
  /lib64/libguile.so.17 : () + 0x71653
  /lib64/libguile.so.17 : () + 0x3f5be
  /lib64/libguile.so.17 : scm_c_catch() + 0x161
  /lib64/libguile.so.17 : scm_i_with_continuation_barrier() + 0xb5
  /lib64/libguile.so.17 : scm_c_with_continuation_barrier() + 0x44
  /lib64/libguile.so.17 : scm_i_with_guile_and_parent() + 0x3a
  /lib64/libguile.so.17 : scm_boot_guile() + 0x39
  texmacs.bin() [0x4c8fdd]
  texmacs.bin() [0x47b5a6]
  /lib64/libc.so.6 : () + 0x2d560
  /lib64/libc.so.6 : __libc_start_main() + 0x7c
  texmacs.bin() [0x475575]

terminate called after throwing an instance of 'string'
Aborted (core dumped)

Jeroen Wouters <jeronim>
Group Member
Thu 27 Jan 2022 06:32:49 AM UTC, comment #2: 

Do you have some crash logs to look at?

Massimiliano Gubinelli <mgubi>
Group administrator
Fri 21 Jan 2022 10:08:15 AM UTC, comment #1: 

According to gdb the segmentation fault happens on line 57 of `QTMWindow.cpp` in side `void QTMWindow::moveEvent (QMoveEvent * event)`. This is with Qt 5.15.2.

The problem does not, in fact, seem to be related to unsaved changes. An apparently reliable way of triggering it is to open about 10 to 15 new blank documents in separate windows and then closing one of them.

Jeroen Wouters <jeronim>
Group Member
Thu 20 Jan 2022 10:40:41 PM UTC, original submission:  

With buffer management set to `Documents in separate windows`, I am seeing occasional segmentation faults when closing documents.

It seems to happen particularly when discarding documents with unsaved changes.

It is difficult to reproduce the problem, but the most reliable way I have found so far is to open a large number (>5?) of new windows, make changes in them and then close them without saving the changes, in rapid succession.

Jeroen Wouters <jeronim>
Group Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #53228:  texmacs-bt.txt added by jeronim (6KiB - text/plain)
file #53229:  texmacs-bt.html added by jeronim (10KiB - text/html)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by vdhoeven (Posted a comment)
  • -email is unavailable- added by pjoyez (Posted a comment)
  • -email is unavailable- added by mgubi (Posted a comment)
  • -email is unavailable- added by jeronim (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-08-07 vdhoeven CategoryNone Qt port
        Priority5 - Normal 7 - High
        StatusNone Ready For Test
        Assigned toNone mgubi
    2022-05-19 jeronim Attached File- Added texmacs-bt.txt, #53228
        Attached File- Added texmacs-bt.html, #53229

    Back to the top

    Powered by Savane 3.13-ee12.
    Corresponding source code