From 3563f51309cc5d7c25983c05d5bdd54292cd962f Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Wed, 19 Jun 2019 11:40:21 +0200 Subject: [PATCH] print a warning when invoking the scripting API's sleep() Summary: the sleep is implemented with a nested event loop which may result in segfaults when something in the new loop stack accesses objects from the original loop stack that are presently in a bad state because they were not meant to be accessed (and only can because of the nesting). to aid in debugging let's leave a trace of the fact that sleep was used when in fact, using sleep is super risky. Test Plan: warning gets printed when sleeping Reviewers: mart Reviewed By: mart Subscribers: davidedmundson, plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D21895 --- shell/scripting/appinterface.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shell/scripting/appinterface.cpp b/shell/scripting/appinterface.cpp index a0ad73cf4..631168a66 100644 --- a/shell/scripting/appinterface.cpp +++ b/shell/scripting/appinterface.cpp @@ -159,6 +159,13 @@ bool AppInterface::coronaLocked() const void AppInterface::sleep(int ms) { + // The nested eventloop here may cause crashes when for example loading a + // LnF because the script runs out of the QML stack. Opening an eventloop + // there and processing QML events may result in touching members objects + // that were meant to be deleted but haven't yet, because the parent event + // loop hasn't returned yet. + qWarning() << "Scripted sleeping starts a nested event loop." \ + " This can cause process instability. Use with care!"; QEventLoop loop; QTimer::singleShot(ms, &loop, &QEventLoop::quit); loop.exec(QEventLoop::ExcludeUserInputEvents);