From 93affd9ff660456bde2d380788ea8ebfabb0f1c3 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 26 Jan 2015 15:53:15 +0100 Subject: Canvas: don't crash when getContext("2d") is called on destruction. We'd assume that a Window existed when that's not always the case. For example: import QtQuick 2.4 import QtQuick.Window 2.2 Window { Loader { sourceComponent: Canvas { Component.onDestruction: getContext("2d") } Component.onCompleted: active = false } } Change-Id: I5f30876e21ced5658adfa3bac494fd4196e0a7e3 Task-number: QTBUG-42222 Reviewed-by: Ulf Hermann --- src/quick/items/context2d/qquickcanvasitem.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/quick') diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp index c31b7726c4..4b28517701 100644 --- a/src/quick/items/context2d/qquickcanvasitem.cpp +++ b/src/quick/items/context2d/qquickcanvasitem.cpp @@ -1124,6 +1124,9 @@ bool QQuickCanvasItem::createContext(const QString &contextType) { Q_D(QQuickCanvasItem); + if (!window()) + return false; + if (contextType == QLatin1String("2d")) { if (d->contextType.compare(QLatin1String("2d"), Qt::CaseInsensitive) != 0) { d->contextType = QLatin1String("2d"); -- cgit v1.2.3