summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authormread <qt-info@nokia.com>2011-11-18 16:21:07 (GMT)
committermread <qt-info@nokia.com>2011-11-21 09:18:00 (GMT)
commitbd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f (patch)
tree76f1e7ef0a0a164d2d1d0dc289a0982ea0547b66 /src/declarative
parent52a93f068d2869fbe4e4deae2ed704d683e12834 (diff)
downloadQt-bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f.zip
Qt-bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f.tar.gz
Qt-bd5dfa8fd2f4d5dc4a1fe0984a53b966cff6470f.tar.bz2
Surviving out of memory in Qt Quick app
The QtQuickPlayground app contains a version of samegame which allow the user to edit the code. By setting the ball size to 8, the app can run out of memory. This leaves it in a pretty bad state. But apps on Symbian shouldn't crash due to OOM and should allow some operation. This change fixes the immediate OOM crashes in declarative, gui and corelib. It shows warning dialogs which explain what has gone wrong and leaves the app in a state that can be exited cleanly from the Symbian task list. Task-number: QT-5319 Reviewed-by: Shane Kearns Reviewed-by: Gareth Stockwell Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp102
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp4
-rw-r--r--src/declarative/qml/qpodvector_p.h4
3 files changed, 59 insertions, 51 deletions
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index f423f50..0d892a2 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -936,50 +936,37 @@ void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeEnginePrivate *engi
void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePriv, ConstructionState *state)
{
if (state->completePending) {
-
- for (int ii = 0; ii < state->bindValues.count(); ++ii) {
- QDeclarativeEnginePrivate::SimpleList<QDeclarativeAbstractBinding> bv =
- state->bindValues.at(ii);
- for (int jj = 0; jj < bv.count; ++jj) {
- if(bv.at(jj)) {
- // XXX akennedy
- bv.at(jj)->m_mePtr = 0;
- bv.at(jj)->setEnabled(true, QDeclarativePropertyPrivate::BypassInterceptor |
- QDeclarativePropertyPrivate::DontRemoveBinding);
+ QT_TRY {
+ for (int ii = 0; ii < state->bindValues.count(); ++ii) {
+ QDeclarativeEnginePrivate::SimpleList<QDeclarativeAbstractBinding> bv =
+ state->bindValues.at(ii);
+ for (int jj = 0; jj < bv.count; ++jj) {
+ if(bv.at(jj)) {
+ // XXX akennedy
+ bv.at(jj)->m_mePtr = 0;
+ bv.at(jj)->setEnabled(true, QDeclarativePropertyPrivate::BypassInterceptor |
+ QDeclarativePropertyPrivate::DontRemoveBinding);
+ }
}
+ QDeclarativeEnginePrivate::clear(bv);
}
- QDeclarativeEnginePrivate::clear(bv);
- }
- for (int ii = 0; ii < state->parserStatus.count(); ++ii) {
- QDeclarativeEnginePrivate::SimpleList<QDeclarativeParserStatus> ps =
- state->parserStatus.at(ii);
+ for (int ii = 0; ii < state->parserStatus.count(); ++ii) {
+ QDeclarativeEnginePrivate::SimpleList<QDeclarativeParserStatus> ps =
+ state->parserStatus.at(ii);
- for (int jj = ps.count - 1; jj >= 0; --jj) {
- QDeclarativeParserStatus *status = ps.at(jj);
- if (status && status->d) {
- status->d = 0;
- status->componentComplete();
+ for (int jj = ps.count - 1; jj >= 0; --jj) {
+ QDeclarativeParserStatus *status = ps.at(jj);
+ if (status && status->d) {
+ status->d = 0;
+ status->componentComplete();
+ }
}
+ QDeclarativeEnginePrivate::clear(ps);
}
- QDeclarativeEnginePrivate::clear(ps);
- }
-
- for (int ii = 0; ii < state->finalizedParserStatus.count(); ++ii) {
- QPair<QDeclarativeGuard<QObject>, int> status = state->finalizedParserStatus.at(ii);
- QObject *obj = status.first;
- if (obj) {
- void *args[] = { 0 };
- QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod,
- status.second, args);
- }
- }
- //componentComplete() can register additional finalization objects
- //that are then never handled. Handle them manually here.
- if (1 == enginePriv->inProgressCreations) {
- for (int ii = 0; ii < enginePriv->finalizedParserStatus.count(); ++ii) {
- QPair<QDeclarativeGuard<QObject>, int> status = enginePriv->finalizedParserStatus.at(ii);
+ for (int ii = 0; ii < state->finalizedParserStatus.count(); ++ii) {
+ QPair<QDeclarativeGuard<QObject>, int> status = state->finalizedParserStatus.at(ii);
QObject *obj = status.first;
if (obj) {
void *args[] = { 0 };
@@ -987,17 +974,38 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri
status.second, args);
}
}
- enginePriv->finalizedParserStatus.clear();
- }
- while (state->componentAttached) {
- QDeclarativeComponentAttached *a = state->componentAttached;
- a->rem();
- QDeclarativeData *d = QDeclarativeData::get(a->parent());
- Q_ASSERT(d);
- Q_ASSERT(d->context);
- a->add(&d->context->componentAttached);
- emit a->completed();
+ //componentComplete() can register additional finalization objects
+ //that are then never handled. Handle them manually here.
+ if (1 == enginePriv->inProgressCreations) {
+ for (int ii = 0; ii < enginePriv->finalizedParserStatus.count(); ++ii) {
+ QPair<QDeclarativeGuard<QObject>, int> status = enginePriv->finalizedParserStatus.at(ii);
+ QObject *obj = status.first;
+ if (obj) {
+ void *args[] = { 0 };
+ QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod,
+ status.second, args);
+ }
+ }
+ enginePriv->finalizedParserStatus.clear();
+ }
+
+ while (state->componentAttached) {
+ QDeclarativeComponentAttached *a = state->componentAttached;
+ a->rem();
+ QDeclarativeData *d = QDeclarativeData::get(a->parent());
+ Q_ASSERT(d);
+ Q_ASSERT(d->context);
+ a->add(&d->context->componentAttached);
+ emit a->completed();
+ }
+ } QT_CATCH(const std::exception&) {
+ state->bindValues.clear();
+ state->parserStatus.clear();
+ state->finalizedParserStatus.clear();
+ state->completePending = false;
+ enginePriv->inProgressCreations--;
+ QT_RETHROW;
}
state->bindValues.clear();
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 1417b78..89a9809 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -1202,8 +1202,8 @@ void QDeclarativeData::setBindingBit(QObject *obj, int bit)
int arraySize = (props + 31) / 32;
int oldArraySize = bindingBitsSize / 32;
- bindingBits = (quint32 *)realloc(bindingBits,
- arraySize * sizeof(quint32));
+ bindingBits = (quint32 *)q_check_ptr(realloc(bindingBits,
+ arraySize * sizeof(quint32)));
memset(bindingBits + oldArraySize,
0x00,
diff --git a/src/declarative/qml/qpodvector_p.h b/src/declarative/qml/qpodvector_p.h
index 7b50463..a055d17 100644
--- a/src/declarative/qml/qpodvector_p.h
+++ b/src/declarative/qml/qpodvector_p.h
@@ -89,7 +89,7 @@ public:
void insert(int idx, const T &v) {
if (m_count == m_capacity) {
m_capacity += Increment;
- m_data = (T *)realloc(m_data, m_capacity * sizeof(T));
+ m_data = (T *)q_check_ptr(realloc(m_data, m_capacity * sizeof(T)));
}
int moveCount = m_count - idx;
if (moveCount)
@@ -101,7 +101,7 @@ public:
void reserve(int count) {
if (count >= m_capacity) {
m_capacity = (count + (Increment-1)) & (0xFFFFFFFF - Increment + 1);
- m_data = (T *)realloc(m_data, m_capacity * sizeof(T));
+ m_data = (T *)q_check_ptr(realloc(m_data, m_capacity * sizeof(T)));
}
}