Skip to content

Disable native calls if an object is disposed. #345

Open
@fcunilim

Description

@fcunilim

Describe the bug

Stepping through harmless code crashes the application.

To Reproduce

Just try the following code. Place a breakpoint on the first line and hit F10 to execute the code line by line until you reach (or try to reach) the third line:

    final image = cv.Mat.zeros(600, 800, cv.MatType.CV_8UC3);
    image.dispose();
    print('After dispose().');

Immediately after executing image.dispose(), using F10 on Visual Studio Code, the application crashes:

F/libc    (25616): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x381c30bec81 in tid 25701 (1.ui), pid 25616 (ple.application)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'motorola/sabahl_ge/sabahl:13/TLAS33.105-285-6/105-285-6:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2025-03-09 19:36:01.551311735+0100
Process uptime: 53s
Cmdline: com.example.application
pid: 25616, tid: 25701, name: 1.ui  >>> com.example.application <<<
uid: 10266
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x00000381c30bec81
    x0  00000381c30bec81  x1  0000007500000000  x2  00000381c30bec81  x3  000000000000501a
    x4  000000750000a4b1  x5  0000000000000000  x6  000000750b786f41  x7  0000000000000002
    x8  00000381c30bec81  x9  00000074eb32fd88  x10 00000076e55718a0  x11 00000000ffffffff
    x12 0000000000000000  x13 0000000000000000  x14 00000075007ca010  x15 000000776b858d40
    x16 00000074ec425760  x17 00000074eb32fdac  x18 000000776b078000  x19 000000776b858d40
    x20 00000381c30bec81  x21 b4000076c9da1000  x22 0000007500008081  x23 000000750ba1d4d9
    x24 00000074eb32fd88  x25 000000776b679000  x26 b4000076c9da1000  x27 000000750c1f0290
    x28 0000000800000075  x29 000000776b858d30
    lr  00000074eb32fda0  sp  000000776b858d10  pc  00000074eb32fdb8  pst 0000000020000000
backtrace:
      #00 pc 000000000072fdb8  /data/app/~~8SwqNWiuFj86YZNj7aD4nw==/com.example.application-IfBt3mdq7GiPdmPK4aHc9w==/base.apk!libdartcv.so (cv::Mat::type() const+12) (BuildId: e01ba305a24c6a1dd51663920c3735f6f30ee3d1)
      #01 pc 000000000072fd9c  /data/app/~~8SwqNWiuFj86YZNj7aD4nw==/com.example.application-IfBt3mdq7GiPdmPK4aHc9w==/base.apk!libdartcv.so (cv_Mat_type+20) (BuildId: e01ba305a24c6a1dd51663920c3735f6f30ee3d1)
      #02 pc 00000000000075a4  [anon:dart-code]
Lost connection to device.

Exited.

I am getting the same problem using valid JPEG bytes with the following code:

    final image = cv.imdecode(jpegBytes, cv.IMREAD_UNCHANGED);
    image.dispose();

With the code above, I am getting a similar native stack trace ((cv::Mat::type() const+12) and (cv_Mat_type+20)).

Expected behavior

No crash.

Desktop (please complete the following information):

  • OS: Windows 11 24H2

Smartphone (please complete the following information):

  • Device: Android 13
  • ABI Version: arm64-v8a

This can be reproduced when running natively on Windows, too.

Using Flutter 3.27.3 (also tried 3.27.4), Visual Studio Code 1.98, Dart/Flutter extensions 3.106.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions