rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
112 stars 14 forks source link

Crash when using `imencode` on windows #68

Closed Hexer10 closed 4 months ago

Hexer10 commented 4 months ago

Hi there, thanks for the nice project.

I'm experiencing a crash when using the imencode function. I've tried running the code on windows both in plain Dart and on flutter and result is the same, the full code of the crash is the following:

void main()  {
  final img = File('img.jpg').readAsBytesSync(); // img.jpg is a standard jpeg image
  final mat = imdecode(img, IMREAD_COLOR);
  final data = imencode('jpg', mat); // <-- crash
}

The log printed in the console is:

===== CRASH =====
ExceptionCode=-1073741819, ExceptionFlags=0, ExceptionAddress=00007FFC977AE081
version=3.5.0-155.0.dev (dev) (Tue May 14 17:03:03 2024 -0700) on "windows_x64"
pid=13264, thread=33940, isolate_group=main(0000000002E46B60), isolate=main(0000000002E5C6F0)
os=windows, arch=x64, comp=no, sim=no
isolate_instructions=7ff618f89f70, vm_instructions=7ff618f89f80
fp=1eadef80, sp=1eadee90, pc=7ffc977ae081
  pc 0x00007ffc977ae081 fp 0x000000001eadef80 Unknown symbol
  // ...
  pc 0x0000000002782f9f fp 0x000000001eadf560 Unknown symbol
  pc 0x00007ff6190b9c1a fp 0x000000001eadfd01 Dart_DetectNullSafety+0x128d9a
-- End of DumpStackTrace
  pc 0x0000000000000000 fp 0x000000001eadef80 sp 0x0000000000000000 Cannot find code object
  pc 0x00000000041ccdb2 fp 0x000000001eadefc8 sp 0x000000001eadef90 [Optimized] CvNative.init:_VecUChar_NewFromVec@66300349.#ffiClosure794
  pc 0x00000000041cc8e8 fp 0x000000001eadf030 sp 0x000000001eadefd8 [Unoptimized] CvNative.VecUChar_NewFromVec
  pc 0x00000000041cc794 fp 0x000000001eadf070 sp 0x000000001eadf040 [Unoptimized] new VecUChar.fromVec.<anonymous closure>
  pc 0x00000000041ba596 fp 0x000000001eadf0b0 sp 0x000000001eadf080 [Unoptimized] cvRun
  pc 0x00000000041cc66f fp 0x000000001eadf0f0 sp 0x000000001eadf0c0 [Unoptimized] new VecUChar.fromVec
  pc 0x00000000041ca085 fp 0x000000001eadf140 sp 0x000000001eadf100 [Unoptimized] imencode.<anonymous closure>
  pc 0x00000000041c96b1 fp 0x000000001eadf1e0 sp 0x000000001eadf150 [Unoptimized] using
  pc 0x00000000041c943d fp 0x000000001eadf260 sp 0x000000001eadf1f0 [Unoptimized] imencode
  pc 0x00000000041ae21c fp 0x000000001eadf2b0 sp 0x000000001eadf270 [Unoptimized] main
  pc 0x00000000041ae126 fp 0x000000001eadf2d8 sp 0x000000001eadf2c0 [Unoptimized] main
  pc 0x00000000041ae05a fp 0x000000001eadf338 sp 0x000000001eadf2e8 [Unoptimized] _Closure@0150898.dyn:call
  pc 0x00000000041acf13 fp 0x000000001eadf378 sp 0x000000001eadf348 [Unoptimized] _delayEntrypointInvocation@1026248.<anonymous closure>
  pc 0x00000000041acc5d fp 0x000000001eadf3e0 sp 0x000000001eadf388 [Unoptimized] _Closure@0150898.dyn:call
  pc 0x00000000041abd0c fp 0x000000001eadf438 sp 0x000000001eadf3f0 [Unoptimized] _RawReceivePort@1026248._handleMessage@1026248
  pc 0x0000000002782f9f fp 0x000000001eadf560 sp 0x000000001eadf448 [Stub] InvokeDartCode

The specific code running before the program crashes it's the following: https://github.com/rainyl/opencv_dart/blob/822c0f66057f575cddc2be89c8becb85d90f5605/lib/src/core/vec.dart#L125-L130 specifically CFFI.VecUChar_NewFromVec(ptr, p) -> _VecUChar_NewFromVec(vec, rval);

Desktop (please complete the following information):

rainyl commented 4 months ago

https://docs.opencv.org/4.9.0/d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63

note the 'ext' parameter must include a leading period, so it should be imencode('.jpg', mat);

but the exception is not friendly, i will try to make it more concise and friendly.

Hexer10 commented 4 months ago

https://docs.opencv.org/4.9.0/d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63

note the 'ext' parameter must include a leading period, so it should be imencode('.jpg', mat);

but the exception is not friendly, i will try to make it more concise and friendly.

Thanks for the help I totally missed the leading dot part.