Skip to content
Commit ffe262ab authored by Noah Davis's avatar Noah Davis 🌵
Browse files

Make CaptureWindows with unique_ptr, move list of windows to SpectacleWindow

unique_ptr will help prevent leaks when SpectacleCore is destroyed.

Having the list of windows in SpectacleWindow makes it possible to add
an remove windows from the constructor and destructor rather than
manually syncronizing them with m_captureWindows and m_viewerWindow in
SpectacleCore.

Also move connections and event filter installation for SelectionEditor
and CaptureWindow to CaptureWindow's constructor and destructor. We can
get rid of captureWindowAdded and captureWindowRemoved and remove the 2
connections for handling those 2 signals.
parent 7228df57
  • Developer

    @ndavis this commit makes spectacle reproducibly crash for me when I accept a rectangular region screenshot.

    Application: Spectacle (spectacle), signal: Segmentation fault
    Content of s_kcrashErrorMessage: std::unique_ptr<char []> = {get() = 0x0}
    [KCrash Handler]
    #5  std::default_delete<CaptureWindow>::operator()(CaptureWindow*) const (__ptr=0x21, this=<optimized out>) at /usr/include/c++/12/bits/unique_ptr.h:89
    #6  std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >::~unique_ptr() (this=0x23d4b28, __in_chrg=<optimized out>) at /usr/include/c++/12/bits/unique_ptr.h:396
    #7  std::__new_allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > >::destroy<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > >(std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >*) (__p=0x23d4b28, this=0x7ffd64adecf8) at /usr/include/c++/12/bits/new_allocator.h:181
    #8  std::allocator_traits<std::allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > > >::destroy<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > >(std::allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > >&, std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >*) (__p=0x23d4b28, __a=...) at /usr/include/c++/12/bits/alloc_traits.h:535
    #9  std::vector<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >, std::allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > > >::_M_erase(__gnu_cxx::__normal_iterator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >*, std::vector<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >, std::allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > > > >) (this=this@entry=0x7ffd64adecf8, __position=Python Exception <class 'gdb.error'>: value has been optimized out
    , __position@entry=std::unique_ptr<CaptureWindow> = {get() = 0x0}) at /usr/include/c++/12/bits/vector.tcc:181
    #10 0x000000000044ae89 in std::vector<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >, std::allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > > >::erase(__gnu_cxx::__normal_iterator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > const*, std::vector<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> >, std::allocator<std::unique_ptr<CaptureWindow, std::default_delete<CaptureWindow> > > > >) (__position=std::unique_ptr<CaptureWindow> = {get() = 0x0}, this=0x7ffd64adecf8) at /usr/include/c++/12/bits/stl_vector.h:1530
    #11 SpectacleCore::deleteWindows() (this=0x7ffd64adec90) at /home/nate/kde/src/spectacle/src/SpectacleCore.cpp:853
    #12 SpectacleCore::deleteWindows() (this=0x7ffd64adec90) at /home/nate/kde/src/spectacle/src/SpectacleCore.cpp:845
    #13 0x000000000044aec5 in SpectacleCore::initViewerWindow(ViewerWindow::Mode) (this=this@entry=0x7ffd64adec90, mode=mode@entry=ViewerWindow::Image) at /home/nate/kde/src/spectacle/src/SpectacleCore.cpp:837
    #14 0x0000000000450832 in SpectacleCore::onScreenshotUpdated(QPixmap const&) (this=0x7ffd64adec90, thePixmap=<optimized out>) at /home/nate/kde/src/spectacle/src/SpectacleCore.cpp:612
    #15 0x00007fb36ccdbc26 in void doActivate<false>(QObject*, int, void**) () at /lib64/libQt5Core.so.5
    #16 0x0000000000428d95 in SpectacleCore::grabDone(QPixmap const&) (this=this@entry=0x7ffd64adec90, _t1=...) at /home/nate/kde/build/spectacle/src/spectacle_autogen/EWIEGA46WW/moc_SpectacleCore.cpp:432
    #17 0x000000000045d19e in SelectionEditor::acceptSelection() (this=0x4cd2d0 <(anonymous namespace)::Q_QGS_privateSelectionEditorSelf::innerFunction()::holder>) at /home/nate/kde/src/spectacle/src/Gui/SelectionEditor.cpp:612
    #18 0x000000000045d2d7 in SelectionEditor::keyPressEvent(QQuickItem*, QKeyEvent*) (this=0x4cd2d0 <(anonymous namespace)::Q_QGS_privateSelectionEditorSelf::innerFunction()::holder>, item=<optimized out>, event=0x7ffd64ade880) at /home/nate/kde/src/spectacle/src/Gui/SelectionEditor.cpp:682
    #19 0x000000000045d556 in SelectionEditor::eventFilter(QObject*, QEvent*) (this=0x4cd2d0 <(anonymous namespace)::Q_QGS_privateSelectionEditorSelf::innerFunction()::holder>, watched=<optimized out>, event=0x7ffd64ade880) at /home/nate/kde/src/spectacle/src/Gui/SelectionEditor.cpp:644
    #20 0x00007fb36cca8041 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () at /lib64/libQt5Core.so.5
    #21 0x00007fb36d9aed52 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /lib64/libQt5Widgets.so.5
    #22 0x00007fb36cca8278 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /lib64/libQt5Core.so.5
    #23 0x00007fb36eea2d1f in QQuickWindowPrivate::deliverKeyEvent(QKeyEvent*) () at /lib64/libQt5Quick.so.5
    #24 0x0000000000461bc1 in SpectacleWindow::keyPressEvent(QKeyEvent*) (this=0x2283720, event=0x7ffd64ade880) at /home/nate/kde/src/spectacle/src/Gui/SpectacleWindow.cpp:510
    #25 0x00007fb36d176365 in QWindow::event(QEvent*) () at /lib64/libQt5Gui.so.5
    #26 0x00007fb36d9aed62 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /lib64/libQt5Widgets.so.5
    #27 0x00007fb36cca8278 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /lib64/libQt5Core.so.5
    #28 0x00007fb36d1673ed in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) () at /lib64/libQt5Gui.so.5
    #29 0x00007fb36d149f1c in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Gui.so.5
    #30 0x00007fb36f31e604 in userEventSourceDispatch(_GSource*, int (*)(void*), void*) () at /lib64/libQt5WaylandClient.so.5
    #31 0x00007fb36a848cbf in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
    #32 0x00007fb36a89e598 in g_main_context_iterate.constprop () at /lib64/libglib-2.0.so.0
    #33 0x00007fb36a845f40 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
    #34 0x00007fb36ccf938a in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
    #35 0x00007fb36cca6cca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /lib64/libQt5Core.so.5
    #36 0x00007fb36ccaed92 in QCoreApplication::exec() () at /lib64/libQt5Core.so.5
    #37 0x0000000000427a11 in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at /home/nate/kde/src/spectacle/src/Main.cpp:105
    [Inferior 1 (process 366668) detached]

    I'm on Wayland; have not tested X11.

  • Author Developer

    Can confirm it only happens on wayland

  • Author Developer

    fixed

  • Developer

    Thanks, can confirm!

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment