Qt6 Android QVideoFrame map crash after resume
-
Hi everyone,
I do have a Qt6 (6.5.0) Quick Android application. The application uses the Qt Camera and shows the stream to the VideoOutput element that fills the screen. When the Take frame button is pressed, the backend method setVideoSink is called. There I get a QVideoFrame from the QVideoSink, make a non-const copy, map it (call method map), do some work (or nothing in the case), and unmap (call method 'unmap`).
Everything fine until the app goes to background and is restored (resumed): when the map method is called on the copy frame, the application crashes, with the log:
E libEGL : call to OpenGL ES API with no current context (logged once per thread) W libappCameraProcessor_arm64-v8a.so: Failed to compile shader: W libappCameraProcessor_arm64-v8a.so: Source was: W libappCameraProcessor_arm64-v8a.so: #version 100 06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so: W libappCameraProcessor_arm64-v8a.so: struct buf W libappCameraProcessor_arm64-v8a.so: { W libappCameraProcessor_arm64-v8a.so: mat4 matrix; W libappCameraProcessor_arm64-v8a.so: mat4 colorMatrix; W libappCameraProcessor_arm64-v8a.so: float opacity; W libappCameraProcessor_arm64-v8a.so: float width; W libappCameraProcessor_arm64-v8a.so: float masteringWhite; W libappCameraProcessor_arm64-v8a.so: float maxLum; W libappCameraProcessor_arm64-v8a.so: }; 06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so: W libappCameraProcessor_arm64-v8a.so: uniform buf ubuf; 06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so: W libappCameraProcessor_arm64-v8a.so: varying vec2 texCoord; W libappCameraProcessor_arm64-v8a.so: attribute vec2 vertexTexCoord; W libappCameraProcessor_arm64-v8a.so: attribute vec4 vertexPosition; 06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so: W libappCameraProcessor_arm64-v8a.so: void main() W libappCameraProcessor_arm64-v8a.so: { W libappCameraProcessor_arm64-v8a.so: texCoord = vertexTexCoord; W libappCameraProcessor_arm64-v8a.so: gl_Position = ubuf.matrix * vertexPosition; W libappCameraProcessor_arm64-v8a.so: } 06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so: 06-16 13:32:36.205 18373 18394 W libappCameraProcessor_arm64-v8a.so: W CameraProcesso: 0xebadde09 skipped times: 0 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x78 in tid 18394 (qtMainLoopThrea), pid 18373 (CameraProcessor)
Now, the source code of the application:
Main.qml
import QtQuick.Window import QtMultimedia import QtQuick.Controls import Backend Window { width: 1920 height: 1024 visible: true Camera { id: userCamera focusMode: Camera.FocusModeAuto } CaptureSession { id: viewFinderCaptureSession videoOutput: viewfinder camera: userCamera } VideoOutput { id: viewfinder anchors.fill: parent } Backend{ id: backend objectName: "backend" } Component.onCompleted: userCamera.start() Button { id: processButton onClicked: backend.videSink = viewfinder.videoSink width: 200 height: 50 text: "Take frame" x: 20 y: 20 } }
backend.h
#include <QObject> #include <QVideoSink> #include <QVideoFrame> #include <QVariant> class backend : public QObject { Q_OBJECT public: backend(QObject* _parent = nullptr); Q_INVOKABLE void setVideoSink(QVideoSink* _videoSink); void disconnectSink(); };
backend.cpp
#include "backend.h" #include <QDebug> backend::backend(QObject* _parent): QObject(_parent) { // noting to do... } void backend::setVideoSink(QVideoSink* _videoSink) { auto myFrame = _videoSink->videoFrame(); qDebug() << "map frame; is valid: " << myFrame.isValid() << "isMapped: " << myFrame.isMapped(); myFrame.map(QVideoFrame::MapMode::ReadOnly); // TODO here comes some work ... myFrame.unmap(); }
The Backend is a C++ class registered in the 'main()' function.
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include "backend.h" int main(int argc, char *argv[]) { qmlRegisterType< backend >( "Backend", 1, 0, "Backend" ); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("CameraProcessor", "Main"); QObject::connect(&app, &QGuiApplication::applicationStateChanged, [](Qt::ApplicationState _state){ qDebug() << "State changed to: " << _state; }); return app.exec(); }
What is the problem here? Any idea to fix it? Examples or suggestions?
Thank you!
-
I am facing the exact same issue in a similar setup. Also tried with Qt6.2.8 and the newest Qt6.6, but same issue. @tm_sx Did you find a solution in the meantime?
-
UPDATE: This is a known bug in Qt https://bugreports.qt.io/browse/QTBUG-113616