summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Tisserand <nt@manctl.com>2012-12-09 15:07:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-12 00:18:13 +0100
commitcae858768f7d16b79f3627cd5b077da89dc0c7c9 (patch)
treed7afcc3185fc98bf438d9ac50b72ba0b5cd3bb41
parent88ad6741ddc2b2be1979aad91679fb578efc899a (diff)
Fix crash when mapping coordinates to & from the root item.
The crash triggered by our (supported & documented) use-cases (calling map{From,To}Item with a null value), has been introduced earlier this year, by this change: https://qt.gitorious.org/qt/qt/commit/bec02b3f3 Also: * Clarify QDeclarativeItem::map{From,To}Item statement ordering. * Handle the engine-less item corner case. Change-Id: I33678f7267a4b624bfa61247a643f37ad2ec735d Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 39ec4881..a38938bc 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2627,10 +2627,17 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qr
return 0;
}
- QScriptValue sv = item.engine()->newObject();
-
// If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y);
+
+ // Use the script engine from the passed item, if available. Use this item's one otherwise.
+ QScriptEngine* const se = itemObj ? item.engine() : QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
+
+ // Engine-less items are unlikely, but nevertheless possible. Handle them.
+ if (0 == se)
+ return QScriptValue(QScriptValue::UndefinedValue);
+
+ QScriptValue sv = se->newObject();
sv.setProperty(QLatin1String("x"), p.x());
sv.setProperty(QLatin1String("y"), p.y());
return sv;
@@ -2665,10 +2672,17 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qrea
return 0;
}
- QScriptValue sv = item.engine()->newObject();
-
// If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene()
QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y);
+
+ // Use the script engine from the passed item, if available. Use this item's one otherwise.
+ QScriptEngine* const se = itemObj ? item.engine() : QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this));
+
+ // Engine-less items are unlikely, but nevertheless possible. Handle them.
+ if (0 == se)
+ return QScriptValue(QScriptValue::UndefinedValue);
+
+ QScriptValue sv = se->newObject();
sv.setProperty(QLatin1String("x"), p.x());
sv.setProperty(QLatin1String("y"), p.y());
return sv;