From d36c21aa8f48aed7775a6a047197b6f6f9055430 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 14 Oct 2021 09:23:45 +0200 Subject: SignalTransition: guard against deleted object If the object has been deleted, we can not retrieve the sender and signalIndex anymore. In that case, the only thing we can do is to print a warning. This is impossible to trigger during normal usage from C++, however it can happen in QML, where we do not disconnect handlers soon enough. This issue only exists in Qt 5, as in Qt 6 c249edb83fa67b3e5f711b28923397e66876182d in qtdeclarative and a few other changes take care of it. A testcase for this issue will be added to qtdeclarative. Fixes: QTBUG-65926 Change-Id: I694a77672c311039c4fe238d9e24c91a427e85e3 Reviewed-by: Ulf Hermann --- src/corelib/statemachine/qstatemachine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/corelib/statemachine/qstatemachine.cpp') diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 92d9b67165..a0078b627d 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -3139,7 +3139,10 @@ void QSignalEventGenerator::execute(void **_a) if (machinePrivate->state != QStateMachinePrivate::Running) return; int signalIndex = senderSignalIndex(); - Q_ASSERT(signalIndex != -1); + if (signalIndex == -1) { + qWarning() << "StateMachine: Could not execute transition because originating object has been deleted"; + return; + } machinePrivate->handleTransitionSignal(sender(), signalIndex, _a); } -- cgit v1.2.3