Bug 478015

Summary: KPhotoAlbum crashes when saving the database after deleting a Category and then dragging one tag over the other in the browser view
Product: [Applications] kphotoalbum Reporter: Victor Lobo <victor.ip.lobo>
Component: BrowserAssignee: KPhotoAlbum Bugs <kpabugs>
Status: REPORTED ---    
Severity: crash CC: schleth_es
Priority: NOR    
Version: GIT master   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Victor Lobo 2023-12-04 00:52:43 UTC
SUMMARY
KPhotoAlbum crashes when saving the database after deleting a Category and then dragging one tag over the other in the browser view.

Related to bug 477532


STEPS TO REPRODUCE
1. Open KPhotoAlbum (kphotoalbum --demo)
2. From the main browser window click on the Places icon to go the list of Places view
3. From the main menu go to Settings > Configure KPhotoAlbum... > Categories
4. (Save the DB now if needed) and Delete the Places category
5. Click OK to confirm deletion
6. Click OK to close the Settings window
7. From the Places browser view drag one tag over the other (for example drag Bridgeport over New York in the demo)
8. Save the database (Ctrl + S)
9. Crash



OBSERVED RESULT
Crash

EXPECTED RESULT
No crash


SOFTWARE/OS VERSIONS
Linux: openSUSE Tumbleweed 20230906; Kernel Version: 6.4.12-1-default (64-bit)
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10
KPhotoAlbum v5.12 and
KPhotoAlbum development version latest git master kphotoalbum v5.12.0-10-gc2fbf53d


ADDITIONAL INFORMATION
1. Crash is reproducible every time the steps are followed.
2. Crash occurs even in the demo database.




Backtrace:
Application: KPhotoAlbum (kphotoalbum), signal: Segmentation fault

[KCrash Handler]
#4  0x0000000000577c7c in QMap<QString, int>::count (this=0x48, akey=...) at /usr/include/qt5/QtCore/qmap.h:692
#5  0x0000000000576a79 in DB::Category::idForName (this=0x0, name=...) at /home/victor/kphotoalbum/DB/Category.cpp:342
#6  0x00000000005bc625 in DB::FileWriter::saveMemberGroups (this=0x7ffe752bd348, writer=...) at /home/victor/kphotoalbum/DB/XML/FileWriter.cpp:239
#7  0x00000000005ba2e4 in DB::FileWriter::save (this=0x7ffe752bd348, fileName=..., isAutoSave=false) at /home/victor/kphotoalbum/DB/XML/FileWriter.cpp:98
#8  0x0000000000588639 in DB::ImageDB::save (this=0x1680220, fileName=..., isAutoSave=false) at /home/victor/kphotoalbum/DB/ImageDB.cpp:673
#9  0x0000000000537c33 in MainWindow::Window::slotSave (this=0x13db040) at /home/victor/kphotoalbum/MainWindow/Window.cpp:537
#10 0x000000000054f4ce in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (MainWindow::Window::*)()>::call(void (MainWindow::Window::*)(), MainWindow::Window*, void**) (f=(void (MainWindow::Window::*)(MainWindow::Window * const)) 0x537b3e <MainWindow::Window::slotSave()>, o=0x13db040, arg=0x7ffe752bd5c0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:152
#11 0x000000000054eb13 in QtPrivate::FunctionPointer<void (MainWindow::Window::*)()>::call<QtPrivate::List<>, void>(void (MainWindow::Window::*)(), MainWindow::Window*, void**) (f=(void (MainWindow::Window::*)(MainWindow::Window * const)) 0x537b3e <MainWindow::Window::slotSave()>, o=0x13db040, arg=0x7ffe752bd5c0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:185
#12 0x000000000054d28f in QtPrivate::QSlotObject<void (MainWindow::Window::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1, this_=0x17b0a30, r=0x13db040, a=0x7ffe752bd5c0, ret=0x0) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:418
#13 0x00007fc4add25442 in QtPrivate::QSlotObjectBase::call (a=0x7ffe752bd5c0, r=0x13db040, this=0x17b0a30) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#14 doActivate<false> (sender=0x17e77d0, signal_index=4, argv=0x7ffe752bd5c0) at kernel/qobject.cpp:3925
#15 0x00007fc4add1e0af in QMetaObject::activate (sender=sender@entry=0x17e77d0, m=m@entry=0x7fc4aeebacc0 <QAction::staticMetaObject>, local_signal_index=local_signal_index@entry=1, argv=argv@entry=0x7ffe752bd5c0) at kernel/qobject.cpp:3985
#16 0x00007fc4ae99e8b2 in QAction::triggered (this=this@entry=0x17e77d0, _t1=<optimized out>) at .moc/moc_qaction.cpp:376
#17 0x00007fc4ae9a142f in QAction::activate (this=0x17e77d0, event=<optimized out>) at kernel/qaction.cpp:1161
#18 0x00007fc4aea9864a in QAbstractButtonPrivate::click (this=0x17b0d00) at widgets/qabstractbutton.cpp:399
#19 0x00007fc4aea98797 in QAbstractButton::mouseReleaseEvent (this=0x17d53b0, e=0x7ffe752bdb50) at widgets/qabstractbutton.cpp:1045
#20 0x00007fc4aeb9104a in QToolButton::mouseReleaseEvent (this=<optimized out>, e=<optimized out>) at widgets/qtoolbutton.cpp:622
#21 0x00007fc4ae9e6d58 in QWidget::event (this=0x17d53b0, event=0x7ffe752bdb50) at kernel/qwidget.cpp:9045
#22 0x00007fc4ae9a519e in QApplicationPrivate::notify_helper (this=this@entry=0x1172130, receiver=receiver@entry=0x17d53b0, e=e@entry=0x7ffe752bdb50) at kernel/qapplication.cpp:3640
#23 0x00007fc4ae9ad5cf in QApplication::notify (this=<optimized out>, receiver=<optimized out>, e=0x7ffe752bdb50) at kernel/qapplication.cpp:3084
#24 0x00007fc4adced198 in QCoreApplication::notifyInternal2 (receiver=0x17d53b0, event=0x7ffe752bdb50) at kernel/qcoreapplication.cpp:1064
#25 0x00007fc4adced36e in QCoreApplication::sendSpontaneousEvent (receiver=<optimized out>, event=<optimized out>) at kernel/qcoreapplication.cpp:1474
#26 0x00007fc4ae9ab92e in QApplicationPrivate::sendMouseEvent (receiver=receiver@entry=0x17d53b0, event=event@entry=0x7ffe752bdb50, alienWidget=<optimized out>, nativeWidget=0x13db040, buttonDown=buttonDown@entry=0x7fc4aeef2330 <qt_button_down>, lastMouseReceiver=..., spontaneous=true, onlyDispatchEnterLeave=false) at kernel/qapplication.cpp:2622
#27 0x00007fc4ae9ff7ed in QWidgetWindow::handleMouseEvent (this=this@entry=0x168b7c0, event=event@entry=0x7ffe752bde00) at kernel/qwidgetwindow.cpp:684
#28 0x00007fc4aea02d0f in QWidgetWindow::event (this=0x168b7c0, event=0x7ffe752bde00) at kernel/qwidgetwindow.cpp:300
#29 0x00007fc4ae9a519e in QApplicationPrivate::notify_helper (this=<optimized out>, receiver=0x168b7c0, e=0x7ffe752bde00) at kernel/qapplication.cpp:3640
#30 0x00007fc4adced198 in QCoreApplication::notifyInternal2 (receiver=0x168b7c0, event=0x7ffe752bde00) at kernel/qcoreapplication.cpp:1064
#31 0x00007fc4adced36e in QCoreApplication::sendSpontaneousEvent (receiver=<optimized out>, event=<optimized out>) at kernel/qcoreapplication.cpp:1474
#32 0x00007fc4ae17d0db in QGuiApplicationPrivate::processMouseEvent (e=0x1ca5fd0) at kernel/qguiapplication.cpp:2285
#33 0x00007fc4ae15038c in QWindowSystemInterface::sendWindowSystemEvents (flags=flags@entry=...) at kernel/qwindowsysteminterface.cpp:1169
#34 0x00007fc49f0f854a in xcbSourceDispatch (source=<optimized out>) at qxcbeventdispatcher.cpp:105
#35 0x00007fc4aa524f30 in ?? () from /lib64/libglib-2.0.so.0
#36 0x00007fc4aa526b58 in ?? () from /lib64/libglib-2.0.so.0
#37 0x00007fc4aa52720c in g_main_context_iteration () from /lib64/libglib-2.0.so.0
#38 0x00007fc4add460d6 in QEventDispatcherGlib::processEvents (this=0x124cdd0, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#39 0x00007fc4adcebc2b in QEventLoop::exec (this=this@entry=0x7ffe752be130, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#40 0x00007fc4adcf40c0 in QCoreApplication::exec () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#41 0x0000000000472a68 in main (argc=2, argv=0x7ffe752be838) at /home/victor/kphotoalbum/main.cpp:161
[Inferior 1 (process 2862) detached]
Comment 1 Andreas Schleth 2023-12-04 11:47:34 UTC
an even quicker crash for the same problem (no saving required):
1. kphotoalbum --demo
2. delete category "people" in settings - the people icon vanished from the main window
3. click on the places icon
4. delete category "places"
5. on clicking "OK" in the settings dialog - crash
KPA 5.12 git master

=> The delete category should only be available if the main screen is shown. The delete option is unavailable for the Tokens category - so this would be the example to follow.
or
=> After deleting a category that is shown in KPA, immediately revert to the main screen, not allowing any actions on the deleted category.