ftylitak / qzxing

Qt/QML wrapper library for the ZXing library. 1D/2D barcode image processing library
Apache License 2.0
621 stars 340 forks source link

Segmentation fault on android #225

Closed 4s4v1n closed 1 year ago

4s4v1n commented 1 year ago

Hi! Can you please tell me what could be the problem? I ran into the following problem. When using the QZXingFilter module in QML, I get an error libc: fatal signal 11 (sigsegv), code 1 (segv_maperr) error.

Here part of the code, where it uses:

  VideoOutput {
        id: videoOutput
        source: camera
        anchors.fill: parent
        fillMode: VideoOutput.Stretch
        autoOrientation: false
        orientation: -90
        focus: visible // to receive focus and capture key events when visible
        filters: [zfxingFilter]
    }

    QZXingFilter {
        id: zxingFilter
        captureRect: {
            videoOutput.contentRect
        //    videoOutput.sourceRect
        //    return videoOutput.mapRectToSource(
        //                videoOutput.mapNormalizedRectToItem(Qt.rect(0, 0,
        //                                                            1, 1)))
    }

Video output and the filter are in a popup that is opened and closed by the user. This error sometimes occurs when closing the popup. I tried using different versions of the library, 2.3 and 3.3, I compile the library - as a dynamic one. Also when i remove QZXingFilter, application doesn't crashes. This error appears only on android device. I run it on blackview tab 10 with armeabi-v7a on android 11. Also in the code, that i've attached, i used different capture rects (which are commented). Maybe you faced a similar problem?

4s4v1n commented 1 year ago

Finally i found the solution. Problem were with cross using of QML Camera and QZXingFilter and start/stop these camera. So, when i grab image by VideoOutput like in code sample that I've attached, on android devices with architecture armeabi-v7a media buffer cleans too fast. So, sometimes in function decodeImage(const QImage& .....) comes non-null QImage, than check if (image.isNull) passed, but after that data delete from another thread and decodeImage tried to work with reference to non-existing image. After that I've change QImage from const reference to value, but that also didn't worked for me, cause of COW: https://en.wikipedia.org/wiki/Copy-on-write. Than I realized to how correct start/stop QZXingFilter with QML Camera. For QZXingFilter I used "active" property. Hope my self answer probably help somebody.