From 16316391948b09c7249b5094493eeef6b869d9bc Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 17 Nov 2011 15:27:04 +0000 Subject: [PATCH] Fix crash in incubator when a guarded context is deleted Change-Id: Ice7375c344b7e8d0d11cc6ee0bdfdf864ecd7109 Reviewed-by: Kent Hansen --- src/declarative/qml/qdeclarativeincubator.cpp | 1 + src/declarative/qml/qdeclarativevme.cpp | 2 +- .../qdeclarativeincubator/data/contextDelete.qml | 5 +++++ .../tst_qdeclarativeincubator.cpp | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml diff --git a/src/declarative/qml/qdeclarativeincubator.cpp b/src/declarative/qml/qdeclarativeincubator.cpp index 80bdfac..bedf355 100644 --- a/src/declarative/qml/qdeclarativeincubator.cpp +++ b/src/declarative/qml/qdeclarativeincubator.cpp @@ -97,6 +97,7 @@ void QDeclarativeEnginePrivate::incubate(QDeclarativeIncubator &i, QDeclarativeC incubatorList.insert(p); incubatorCount++; + p->vmeGuard.guard(&p->vme); p->changeStatus(QDeclarativeIncubator::Loading); if (incubationController) diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index e39a7c9..8f11b28 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -1455,7 +1455,7 @@ void QDeclarativeVMEGuard::guard(QDeclarativeVME *vme) for (int ii = 0; ii < m_objectCount; ++ii) m_objects[ii] = vme->objects[ii]; - m_contextCount = (vme->rootContext.isNull())?0:1 + vme->states.count(); + m_contextCount = (vme->rootContext.isNull()?0:1) + vme->states.count(); m_contexts = new QDeclarativeGuardedContextData[m_contextCount]; for (int ii = 0; ii < vme->states.count(); ++ii) m_contexts[ii] = vme->states.at(ii).context; diff --git a/tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml b/tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml new file mode 100644 index 0000000..c395207 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeincubator/data/contextDelete.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property int dummy: 12 +} diff --git a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp index 54ca622..efa4626 100644 --- a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp +++ b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,7 @@ private slots: void chainedAsynchronousIfNested(); void chainedAsynchronousIfNestedOnCompleted(); void selfDelete(); + void contextDelete(); private: QDeclarativeIncubationController controller; @@ -975,6 +977,24 @@ void tst_qdeclarativeincubator::selfDelete() } } +// Test that QML doesn't crash if the context is deleted prior to the incubator +// first executing. +void tst_qdeclarativeincubator::contextDelete() +{ + QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext()); + QDeclarativeComponent component(&engine, TEST_FILE("contextDelete.qml")); + + QDeclarativeIncubator incubator; + component.create(incubator, context); + + delete context; + + { + bool b = false; + controller.incubateWhile(&b); + } +} + QTEST_MAIN(tst_qdeclarativeincubator) #include "tst_qdeclarativeincubator.moc" -- 2.7.4