rainyl / opencv_dart

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

In core/mat.dart line 161 under factory Mat.fromVec - the dispose causes a crash if a pointer is sent #248

Closed sysmesh closed 1 month ago

sysmesh commented 1 month ago

Describe the bug When using a VecPoint pointer when calling Mat.fromVec the code crashes without notice or any error log. After debugging the code I've discovered that in core/Mat.php line 161 the dispose causes dart to crash. If you comment it out then the code runs fine without an error.

To Reproduce Steps to reproduce the behavior:

  1. In your code create and populate a Vec type: openCV.Vec? docCnt;

  2. Then try to create a Mat from that vec type: openCV.Mat docCntMat = openCV.Mat.fromVec(docCnt!);

On iOS (checked on simulator and on a physical device - it will cause a crash.

Expected behavior Expected a Mat to be created or a proper thrown exception.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context If you comment out line 161 at core/mat.dart it will work fine: //vec.dispose(); return Mat._(p);

rainyl commented 1 month ago

Well it's so strange...

vec should be copied when creating Mat with Mat.fromVec, and thus safe to dispose.

Wait, do you use docCnt after openCV.Mat.fromVec(docCnt!);? if so it makes sense.

Anyway, I realized that vec should not be freed inside Mat.fromVec, will fix it.

Thanks for your debugging. :)

sysmesh commented 1 month ago

The actual crash happens right when the dispose is called (way before it finishes the function) so I am not trying to use doCnt :-)