Workaround for a Qt crash on reloading menus #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Such random crashes are triggered by Qt →
QMenu::timerEvent()
. Qt doesn't take into account the possibility of dangling pointers inqmenu.cpp
under very rare circumstances, e.g., when the actions of a menu with a visible submenu are recreated too rapidly multiple times (also see https://bugreports.qt.io/browse/QTBUG-77273, although our case is much more complex). That may no be unexpected in a code full of timers and event handling.To avoid dangling pointers, the patch just puts a minimum interval of two seconds between two consecutive reloads.
It also restores the active action on refreshing, such that a reloaded submenu isn't closed anymore (see lxqt/lxqt#2282 and especially @yan12125's report https://gitlab.gnome.org/GNOME/network-manager-applet/-/issues/195).
Finally, it removes a redundant, recursive computation.
Closes lxqt/lxqt-panel#1802
NOTE: I was able to reproduce the crash easily with nm-applet. Before arriving at this workaround, I tried various ideas but could still make lxqt-panel crash in a few minutes. Only this time I can't, in spite of trying for days.