summaryrefslogtreecommitdiffstats
path: root/src
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 07:35:30 +0000
commit24a43429e215a7bfc9c6cecf8f236fdec945dccf (patch)
tree2aea4413ecaa495e3a627ca1803b93789ffc8f1d /src
parent20ecf1a9b9170f7cc0157cd94f71131d15cea4f0 (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.6 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>
Diffstat (limited to 'src')
-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