Bug 468049 - Digikam crash when image quality sorter used - terminate called after throwing an instance of 'cv::Exception'
Summary: Digikam crash when image quality sorter used - terminate called after throwin...
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Maintenance-Quality (show other bugs)
Version: 8.0.0
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-01 21:57 UTC by Petr Schonmann
Modified: 2023-04-03 07:36 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 8.0.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Schonmann 2023-04-01 21:57:47 UTC
SUMMARY
***
When i select 82 images and try Image Quality sort, digikam crashes
***


STEPS TO REPRODUCE
1. Select folder from left menu
2. Select all photos
3. Right click ImageQualitySorter
4. Setup with deep learning
5. Wait some time - CRASH

OBSERVED RESULT
Im digikam console

Qt Concurrent has caught an exception thrown from a worker thread.
This is not supported, exceptions thrown in worker threads must be
caught before control returns to Qt Concurrent.
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.4) ./modules/core/src/matrix.cpp:768: error: (-215:Assertion failed) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function 'Mat'

in GDB

#0  0x00007ffff2f2edb0 in cv::Mat::Mat(cv::Mat const&) () at /lib/x86_64-linux-gnu/libopencv_core.so.4.5d
#1  0x00007ffff2f2f713 in cv::Mat::reshape(int, int) const () at /lib/x86_64-linux-gnu/libopencv_core.so.4.5d
#2  0x00007ffff3976903 in  () at /lib/x86_64-linux-gnu/libopencv_dnn.so.4.5d
#3  0x00007ffff3977384 in  () at /lib/x86_64-linux-gnu/libopencv_dnn.so.4.5d
#4  0x00007ffff393883a in  () at /lib/x86_64-linux-gnu/libopencv_dnn.so.4.5d
#5  0x00007ffff3933742 in  () at /lib/x86_64-linux-gnu/libopencv_dnn.so.4.5d
#6  0x00007ffff3936fa3 in cv::dnn::dnn4_v20211004::Net::forward(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () at /lib/x86_64-linux-gnu/libopencv_dnn.so.4.5d
#7  0x00007ffff6110c1c in Digikam::AestheticDetector::detect(cv::Mat const&) const (this=0x7ffe76ed8080, image=...) at /home/pschonmann/temp/digikam/core/libs/imgqsort/detectors/aesthetic_detector.cpp:48
#8  0x00007ffff610c514 in Digikam::ImageQualityParser::startAnalyse() (this=0x7ffe7400cb40) at /home/pschonmann/temp/digikam/core/libs/imgqsort/imagequalityparser.cpp:92
#9  0x00007ffff78c9d15 in Digikam::ImageQualityTask::run() (this=0x555561ba5ae0) at /home/pschonmann/temp/digikam/core/utilities/maintenance/imagequalitytask.cpp:118
#10 0x00007ffff46cff92 in  () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#11 0x00007ffff46ccca1 in  () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#12 0x00007ffff3e94b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#13 0x00007ffff3f26a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81



EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Maik Qualmann 2023-04-01 22:01:26 UTC
It crashes in OpenCV, your OpenCV-4.5.4 version is probably too old.

Maik
Comment 2 caulier.gilles 2023-04-02 04:57:52 UTC
Git commit 65d25dacab3c0f6379b2c8fe23bbca656c98568a by Gilles Caulier.
Committed on 02/04/2023 at 04:56.
Pushed by cgilles into branch 'master'.

add missing C++ exception with opencv code in DNN part of aesthetic detector

M  +1    -6    core/libs/imgqsort/detectors/abstract_detector.cpp
M  +1    -1    core/libs/imgqsort/detectors/abstract_detector.h
M  +23   -8    core/libs/imgqsort/detectors/aesthetic_detector.cpp
M  +1    -1    core/libs/imgqsort/detectors/aesthetic_detector.h

https://invent.kde.org/graphics/digikam/commit/65d25dacab3c0f6379b2c8fe23bbca656c98568a
Comment 3 caulier.gilles 2023-04-02 10:10:08 UTC
Petr,

AppImage 8.0.0 pre-release bundle is updated with last changes from Maik:

https://files.kde.org/digikam/

Please test and give us a feedback.

Best regards

Gilles Caulier
Comment 4 Petr Schonmann 2023-04-02 18:31:58 UTC
Thanks for new 8.0.0 builds. But DK is still crashing.
---
Thread 99 "Thread (pooled)" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffe567fc640 (LWP 264083)]
0x00007ffff1ea547e in __GI___libc_free (mem=0x7ffe00000004) at ./malloc/malloc.c:3368
3368	./malloc/malloc.c: Adresář nebo soubor neexistuje.
(gdb) bt
#0  0x00007ffff1ea547e in __GI___libc_free (mem=0x7ffe00000004) at ./malloc/malloc.c:3368
#1  0x00007fffedb50499 in cv::dnn::dnn4_v20220524::Layer::~Layer() () from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#2  0x00007fffedb50519 in cv::dnn::dnn4_v20220524::Layer::~Layer() () from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#3  0x00007ffff72b2fba in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7ffe60003290) at ././/include/c++/7/bits/shared_ptr_base.h:154
#4  0x00007fffedc3801f in cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively(int, std::map<int, cv::dnn::dnn4_v20220524::detail::LayerShapes, std::less<int>, std::allocator<std::pair<int const, cv::dnn::dnn4_v20220524::detail::LayerShapes> > >&) () from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#5  0x00007fffedc3a076 in cv::dnn::dnn4_v20220524::Net::Impl::getLayersShapes(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, std::map<int, cv::dnn::dnn4_v20220524::detail::LayerShapes, std::less<int>, std::allocator<std::pair<int const, cv::dnn::dnn4_v20220524::detail::LayerShapes> > >&) () from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#6  0x00007fffedc3eb99 in cv::dnn::dnn4_v20220524::Net::Impl::allocateLayers(std::vector<cv::dnn::dnn4_v20220524::detail::LayerPin, std::allocator<cv::dnn::dnn4_v20220524::detail::LayerPin> > const&) ()
   from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#7  0x00007fffedc42ad8 in cv::dnn::dnn4_v20220524::Net::Impl::setUpNet(std::vector<cv::dnn::dnn4_v20220524::detail::LayerPin, std::allocator<cv::dnn::dnn4_v20220524::detail::LayerPin> > const&) ()
   from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#8  0x00007fffedc4316d in cv::dnn::dnn4_v20220524::Net::Impl::forward(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#9  0x00007fffedc280f9 in cv::dnn::dnn4_v20220524::Net::forward(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /tmp/.mount_digiKapnXfc9/usr/lib/libopencv_dnn.so.406
#10 0x00007ffff58742a5 in Digikam::AestheticDetector::detect (this=this@entry=0x7ffe5a7d16c0, image=...) at /b/master/dktemp/digikam-master/core/libs/imgqsort/detectors/aesthetic_detector.cpp:50
#11 0x00007ffff5871de1 in Digikam::ImageQualityParser::startAnalyse (this=this@entry=0x7ffe58001550) at /b/master/dktemp/digikam-master/core/libs/imgqsort/imagequalityparser.cpp:92
#12 0x00007ffff747310f in Digikam::ImageQualityTask::run (this=0x55555910ea30) at /b/master/dktemp/digikam-master/core/utilities/maintenance/imagequalitytask.cpp:118
#13 0x00007ffff26b9bca in ?? () from /tmp/.mount_digiKapnXfc9/usr/lib/libQt5Core.so.5
#14 0x00007ffff26b61a2 in ?? () from /tmp/.mount_digiKapnXfc9/usr/lib/libQt5Core.so.5
#15 0x00007ffff1e94b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#16 0x00007ffff1f26a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
Comment 5 caulier.gilles 2023-04-02 20:51:32 UTC
Maik,

The crash is reproducible by Petr with the AppImage. It's not an OpenCV version problem.

The message "Qt Concurrent has caught an exception thrown from a worker thread.
This is not supported, exceptions thrown in worker threads must be
caught before control returns to Qt Concurrent." means that the C++ exception must be handle in the top level where Qt::Concurrent is created ?

Gilles
Comment 6 caulier.gilles 2023-04-03 01:53:32 UTC
Petr,

Did you downloaded the DNN model file for the aesthetic detector? (weights_inceptionv3_299.pb).
What's the contents from ~/.local/share/digikam/facesengine ?
Can you copy and paste the debug statement for the console when digikam start (not the gdb trace) ? 
Did you use multi-core option from maintenance tool ?

Gilles Caulier
Comment 7 caulier.gilles 2023-04-03 06:33:32 UTC
I can re produce the crash: it's due to use multicore with static member to host dnn model. I will fix it

Gilles
Comment 8 caulier.gilles 2023-04-03 07:36:53 UTC
Git commit e016a2797e78ebfc6bfdc320435caa50af925127 by Gilles Caulier.
Committed on 03/04/2023 at 07:35.
Pushed by cgilles into branch 'master'.

Use muxtex to protext model in aesthetic parser when multicore is used.
FIXED-IN: 8.0.0

M  +52   -23   core/libs/imgqsort/detectors/aesthetic_detector.cpp
M  +10   -4    core/libs/imgqsort/detectors/aesthetic_detector.h
M  +1    -1    core/libs/imgqsort/imagequalityparser.cpp

https://invent.kde.org/graphics/digikam/commit/e016a2797e78ebfc6bfdc320435caa50af925127