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
wilder-5.17
Harald Sitter 7 years ago
parent 92a6d3f3a3
commit 3563f51309
  1. 7
      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);

Loading…
Cancel
Save