summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Krause <vkrause@kde.org>2023-12-14 17:26:43 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-12-22 14:55:05 +0000
commit3981f59d558689997b37666e414111ed23dc0dae (patch)
treea90944bd80f69033eabbbd911f60f5cc26c721a5
parent5bd1a0b0748ebba72a7e42fe28876b5ae4a79eac (diff)
Reset RHI state on application suspend
This fixes a crash on Android when mapping a QVideoFrame from the camera after the application has been resumed from suspension. Pick-to: 6.5 Fixes: QTBUG-113616 Change-Id: If107c7e8b9595f638034ea0bb05995ce5f096c0d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> Reviewed-by: Bartlomiej Moskal <bartlomiej.moskal@qt.io> (cherry picked from commit c1e2f1e0dcac6d553fbef5a8abe7a652b9b3b70e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 24a43429e215a7bfc9c6cecf8f236fdec945dccf)
-rw-r--r--src/multimedia/video/qvideoframeconverter.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/multimedia/video/qvideoframeconverter.cpp b/src/multimedia/video/qvideoframeconverter.cpp
index 5060ee9ab..2b4945c55 100644
--- a/src/multimedia/video/qvideoframeconverter.cpp
+++ b/src/multimedia/video/qvideoframeconverter.cpp
@@ -35,11 +35,21 @@ struct State
QOffscreenSurface *fallbackSurface = nullptr;
#endif
bool cpuOnly = false;
+#if defined(Q_OS_ANDROID)
+ QMetaObject::Connection appStateChangedConnection;
+#endif
~State() {
+ resetRhi();
+ }
+
+ void resetRhi() {
delete rhi;
+ rhi = nullptr;
#if QT_CONFIG(opengl)
delete fallbackSurface;
+ fallbackSurface = nullptr;
#endif
+ cpuOnly = false;
}
};
@@ -159,6 +169,16 @@ static QRhi *initializeRHI(QRhi *videoFrameRhi)
if (backend == QRhi::OpenGLES2)
params.shareContext = static_cast<const QRhiGles2NativeHandles*>(videoFrameRhi->nativeHandles())->context;
g_state.localData().rhi = QRhi::create(QRhi::OpenGLES2, &params);
+
+#if defined(Q_OS_ANDROID)
+ // reset RHI state on application suspension, as this will be invalid after resuming
+ if (!g_state.localData().appStateChangedConnection) {
+ g_state.localData().appStateChangedConnection = QObject::connect(qApp, &QGuiApplication::applicationStateChanged, qApp, [](auto state) {
+ if (state == Qt::ApplicationSuspended)
+ g_state.localData().resetRhi();
+ });
+ }
+#endif
}
}
#endif