From 345be581007c05164052e27f90fcfaf27a41c743 Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Wed, 6 Dec 2017 19:46:31 +0100 Subject: Fix assert when emitting a signal from a different thread If a signal is emitted more than once in a multithreaded application the QSignalEventGenerator::execute function asserts in the check for a valid signal index. It happens after abandoning the state and all the connections are disconnected. If we have pending signal to be processed the QObject::sender() won't be able to resolve the sender object. Task-number: QTBUG-61463 Change-Id: I9d4b7266c6dddc9ff2e7453b05a6989876ccb332 Reviewed-by: Edward Welbourne --- src/corelib/statemachine/qstatemachine.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/corelib/statemachine') diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 2808ba2ced..c2b5afd241 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -3096,10 +3096,12 @@ int QSignalEventGenerator::qt_metacall(QMetaObject::Call _c, int _id, void **_a) void QSignalEventGenerator::execute(void **_a) { + auto machinePrivate = QStateMachinePrivate::get(qobject_cast(parent())); + if (machinePrivate->state != QStateMachinePrivate::Running) + return; int signalIndex = senderSignalIndex(); Q_ASSERT(signalIndex != -1); - QStateMachine *machine = qobject_cast(parent()); - QStateMachinePrivate::get(machine)->handleTransitionSignal(sender(), signalIndex, _a); + machinePrivate->handleTransitionSignal(sender(), signalIndex, _a); } QSignalEventGenerator::QSignalEventGenerator(QStateMachine *parent) -- cgit v1.2.3