Skip to content

std::bad_optional_access thrown in generated C++ code #9841

@ubruhin

Description

@ubruhin

Bug Description

Our UI tests now randomly fail due to a std::bad_optional_access exception. Strangely I have seen it only on MacOS, and I could not yet reproduce it manually, but I can reproduce it by running the UI tests locally. Maybe it is something timing critical.

On MacOS I could get this crash report:

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	       0x19123c724 __pthread_kill + 8
1   libsystem_pthread.dylib       	       0x191273c28 pthread_kill + 288
2   libsystem_c.dylib             	       0x191181ae8 abort + 180
3   libc++abi.dylib               	       0x19122cb84 abort_message + 132
4   libc++abi.dylib               	       0x19121c3b4 demangling_terminate_handler() + 320
5   libobjc.A.dylib               	       0x190ef303c _objc_terminate() + 160
6   libc++abi.dylib               	       0x19122bf48 std::__terminate(void (*)()) + 16
7   libc++abi.dylib               	       0x19122ed34 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 36
8   libc++abi.dylib               	       0x19122ece0 __cxa_throw + 140
9   librepcb                      	       0x1069bfe7c std::__1::__throw_bad_optional_access[abi:v15006]() + 56 (optional:225)
10  librepcb                      	       0x105909b18 std::__1::optional<vtable::VRcMapped<slint::cbindgen_private::ItemTreeVTable, ui::LibraryListViewItem_root_1025 const>>::value[abi:v15006]() && + 40 (optional:1026)
11  librepcb                      	       0x1059bf960 ui::Component_checked_sw_1032::init(ui::SharedGlobals const*, vtable::VWeak<slint::cbindgen_private::ItemTreeVTable, vtable::Dyn>, unsigned int, unsigned int, ui::LibraryListViewItem_root_1025 const*)::$_291::operator()() const + 56 (slint_generated_appwindow_4.cpp:698)
12  librepcb                      	       0x1059bf910 void slint::private_api::Property<bool>::set_binding<ui::Component_checked_sw_1032::init(ui::SharedGlobals const*, vtable::VWeak<slint::cbindgen_private::ItemTreeVTable, vtable::Dyn>, unsigned int, unsigned int, ui::LibraryListViewItem_root_1025 const*)::$_291>(ui::Component_checked_sw_1032::init(ui::SharedGlobals const*, vtable::VWeak<slint::cbindgen_private::ItemTreeVTable, vtable::Dyn>, unsigned int, unsigned int, ui::LibraryListViewItem_root_1025 const*)::$_291) const::'lambda'(void*, void*)::operator()(void*, void*) const + 32 (slint_properties.h:101)
13  librepcb                      	       0x1059bf8e4 void slint::private_api::Property<bool>::set_binding<ui::Component_checked_sw_1032::init(ui::SharedGlobals const*, vtable::VWeak<slint::cbindgen_private::ItemTreeVTable, vtable::Dyn>, unsigned int, unsigned int, ui::LibraryListViewItem_root_1025 const*)::$_291>(ui::Component_checked_sw_1032::init(ui::SharedGlobals const*, vtable::VWeak<slint::cbindgen_private::ItemTreeVTable, vtable::Dyn>, unsigned int, unsigned int, ui::LibraryListViewItem_root_1025 const*)::$_291) const::'lambda'(void*, void*)::__invoke(void*, void*) + 36 (slint_properties.h:100)
14  liblibrepcbslint.dylib        	       0x11d7abc24 _$LT$i_slint_core..properties..ffi..make_c_function_binding..CFunctionBinding$LT$T$GT$$u20$as$u20$i_slint_core..properties..BindingCallable$GT$::evaluate::hd6b3b5225ff09a73 + 76
15  liblibrepcbslint.dylib        	       0x11d925574 i_slint_core::properties::alloc_binding_holder::evaluate::_$u7b$$u7b$closure$u7d$$u7d$::h5f408faa79687543 + 52
16  liblibrepcbslint.dylib        	       0x11d932254 i_slint_core::properties::_::_$LT$impl$u20$i_slint_core..properties..CURRENT_BINDING$GT$::set::h9bc53b8b4f0c4e8c + 120
17  liblibrepcbslint.dylib        	       0x11d924f3c i_slint_core::properties::alloc_binding_holder::evaluate::h1df8ad173fc9f125 + 60
18  liblibrepcbslint.dylib        	       0x11d92d364 i_slint_core::properties::PropertyHandle::update::_$u7b$$u7b$closure$u7d$$u7d$::hbd29d287d80e0c64 + 192
19  liblibrepcbslint.dylib        	       0x11d9291c0 i_slint_core::properties::PropertyHandle::access::hbaf7a38382953624 + 188
20  liblibrepcbslint.dylib        	       0x11d92b9c8 i_slint_core::properties::PropertyHandle::update::hd8ee602fe35d7265 + 40
21  liblibrepcbslint.dylib        	       0x11d876320 slint_property_update + 60
22  librepcb                      	       0x106962778 slint::private_api::Property<bool>::get() const + 36 (slint_properties.h:91)
23  librepcb                      	       0x1059c12b4 auto ui::Component_checked_sw_1032::user_init()::$_295::operator()<ui::Component_checked_sw_1032*>(ui::Component_checked_sw_1032*) const + 32 (slint_generated_appwindow_4.cpp:730)
24  librepcb                      	       0x1059c1240 void slint::private_api::ChangeTracker::init<ui::Component_checked_sw_1032*, ui::Component_checked_sw_1032::user_init()::$_295, ui::Component_checked_sw_1032::user_init()::$_296>(ui::Component_checked_sw_1032*, ui::Component_checked_sw_1032::user_init()::$_295, ui::Component_checked_sw_1032::user_init()::$_296)::'lambda0'(void*)::operator()(void*) const + 48 (slint_properties.h:335)
25  librepcb                      	       0x1059c1200 void slint::private_api::ChangeTracker::init<ui::Component_checked_sw_1032*, ui::Component_checked_sw_1032::user_init()::$_295, ui::Component_checked_sw_1032::user_init()::$_296>(ui::Component_checked_sw_1032*, ui::Component_checked_sw_1032::user_init()::$_295, ui::Component_checked_sw_1032::user_init()::$_296)::'lambda0'(void*)::__invoke(void*) + 28 (slint_properties.h:333)
26  liblibrepcbslint.dylib        	       0x11d7acea0 i_slint_core::properties::ffi::slint_change_tracker_init::evaluate::_$u7b$$u7b$closure$u7d$$u7d$::h107adbc1b64417c4 + 40
27  liblibrepcbslint.dylib        	       0x11d9326f8 i_slint_core::properties::_::_$LT$impl$u20$i_slint_core..properties..CURRENT_BINDING$GT$::set::hf0cfb9f669739cc1 + 120
28  liblibrepcbslint.dylib        	       0x11d876bac i_slint_core::properties::ffi::slint_change_tracker_init::evaluate::hc68d961e571e9fd6 + 128
29  liblibrepcbslint.dylib        	       0x11d91a6fc i_slint_core::properties::change_tracker::ChangeTracker::run_change_handlers::_$u7b$$u7b$closure$u7d$$u7d$::h27be09c6632ed0ce + 316
30  liblibrepcbslint.dylib        	       0x11d7d9448 std::thread::local::LocalKey$LT$T$GT$::try_with::hd2578adeb98f591b + 132
31  liblibrepcbslint.dylib        	       0x11d7d53a0 std::thread::local::LocalKey$LT$T$GT$::with::hbce8c79c13611e7d + 24
32  liblibrepcbslint.dylib        	       0x11d873e24 i_slint_core::properties::change_tracker::ChangeTracker::run_change_handlers::hb20e748b2b6782a6 + 20
33  liblibrepcbslint.dylib        	       0x11d8f2928 i_slint_core::platform::update_timers_and_animations::hf1a91c6d6f9736d0 + 24
34  liblibrepcbslint.dylib        	       0x11d743c60 i_slint_backend_qt::qt_window::timer_event::h2bea60280ebc909d + 12
35  liblibrepcbslint.dylib        	       0x11d7410a8 i_slint_backend_qt::qt_window::QtWindow::paint_event::h044228145199d8d9 + 140
36  liblibrepcbslint.dylib        	       0x11d748b3c i_slint_backend_qt::qt_window::Slint_paintEvent::_$u7b$$u7b$closure$u7d$$u7d$::h92cee180f2fe496d + 80
37  liblibrepcbslint.dylib        	       0x11d7445c4 Slint_paintEvent + 92
38  liblibrepcbslint.dylib        	       0x11d7988b4 SlintWidget::paintEvent(QPaintEvent*) + 240
39  QtWidgets                     	       0x119a7a7d8 QWidget::event(QEvent*) + 136
40  QtWidgets                     	       0x119a34074 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 252
41  QtWidgets                     	       0x119a35bd8 QApplication::notify(QObject*, QEvent*) + 3592
42  QtCore                        	       0x11b0273b4 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 200
43  QtWidgets                     	       0x119a73828 QWidgetPrivate::sendPaintEvent(QRegion const&) + 72
44  QtWidgets                     	       0x119a6c44c QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) + 2476
45  QtWidgets                     	       0x119a8c040 QWidgetRepaintManager::paintAndFlush() + 2920
46  QtWidgets                     	       0x119a8c20c QWidgetRepaintManager::sync() + 256
47  QtWidgets                     	       0x119a7b008 QWidget::event(QEvent*) + 2232
48  QtWidgets                     	       0x119a34074 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 252
49  QtWidgets                     	       0x119a35bd8 QApplication::notify(QObject*, QEvent*) + 3592
50  QtCore                        	       0x11b0273b4 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 200
51  QtWidgets                     	       0x119a89264 QWidgetRepaintManager::sendUpdateRequest(QWidget*, QWidgetRepaintManager::UpdateTime) + 636
52  QtWidgets                     	       0x119a88f9c void QWidgetRepaintManager::markDirty<QRect>(QRect const&, QWidget*, QWidgetRepaintManager::UpdateTime, QWidgetRepaintManager::BufferState) + 1608
53  QtWidgets                     	       0x119a7d7e4 void QWidgetPrivate::repaint<QRect>(QRect) + 156
54  QtWidgets                     	       0x119a8f9d8 QWidgetWindow::event(QEvent*) + 772
55  QtWidgets                     	       0x119a34074 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 252
56  QtWidgets                     	       0x119a34ff8 QApplication::notify(QObject*, QEvent*) + 552
57  QtCore                        	       0x11b0273b4 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 200
58  QtGui                         	       0x11a8f5668 QPlatformWindow::deliverUpdateRequest() + 104
59  libqcocoa.dylib               	       0x11bbf4bb8 QCocoaWindow::deliverUpdateRequest() + 332
60  libqcocoa.dylib               	       0x11bbdf39c QCocoaScreen::deliverUpdateRequests() + 416
61  libdispatch.dylib             	       0x1910c4400 _dispatch_client_callout + 20
62  libdispatch.dylib             	       0x1910c7884 _dispatch_continuation_pop + 504
63  libdispatch.dylib             	       0x1910dae7c _dispatch_source_invoke + 1588
64  libdispatch.dylib             	       0x1910d2b4c _dispatch_main_queue_drain + 756
65  libdispatch.dylib             	       0x1910d2848 _dispatch_main_queue_callback_4CF + 44
66  CoreFoundation                	       0x191393c88 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
67  CoreFoundation                	       0x1913514a8 __CFRunLoopRun + 1992
68  CoreFoundation                	       0x19135058c CFRunLoopRunSpecific + 612
69  HIToolbox                     	       0x19ab85df4 RunCurrentEventLoopInMode + 292
70  HIToolbox                     	       0x19ab85c30 ReceiveNextEventCommon + 648
71  HIToolbox                     	       0x19ab85988 _BlockUntilNextEventMatchingListInModeWithFilter + 76
72  AppKit                        	       0x19456ff58 _DPSNextEvent + 636
73  AppKit                        	       0x19456f0f4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716
74  AppKit                        	       0x194563558 -[NSApplication run] + 464
75  libqcocoa.dylib               	       0x11bbc78fc QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 1980
76  QtCore                        	       0x11b02f220 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 504
77  QtCore                        	       0x11b027980 QCoreApplication::exec() + 144
78  liblibrepcbslint.dylib        	       0x11d77c670 __cpp_closure_10237296277533982771 + 28
79  liblibrepcbslint.dylib        	       0x11d779ae8 _$LT$i_slint_backend_qt..Backend$u20$as$u20$i_slint_core..platform..Platform$GT$::run_event_loop::hf2abddf2d3fc7af3 + 28
80  liblibrepcbslint.dylib        	       0x11d0801f8 librepcbslint::slint_run_event_loop::_$u7b$$u7b$closure$u7d$$u7d$::h1b6ecf55a8ebdb7b + 100 (lib.rs:65)
81  liblibrepcbslint.dylib        	       0x11d0805bc i_slint_backend_selector::with_platform::_$u7b$$u7b$closure$u7d$$u7d$::h90311622c001c2ad + 72 (lib.rs:150)
82  liblibrepcbslint.dylib        	       0x11d081acc i_slint_core::context::with_global_context::_$u7b$$u7b$closure$u7d$$u7d$::hb267c3bd44eca64f + 168 (context.rs:121)
83  liblibrepcbslint.dylib        	       0x11d08376c std::thread::local::LocalKey$LT$T$GT$::try_with::heea532c9e9ec71db + 168 (local.rs:308)
84  liblibrepcbslint.dylib        	       0x11d083294 std::thread::local::LocalKey$LT$T$GT$::with::h3b5fc02613385b06 + 52 (local.rs:272)
85  liblibrepcbslint.dylib        	       0x11d081410 i_slint_core::context::with_global_context::h05ce47ec82d9d9cf + 44 (context.rs:120)
86  liblibrepcbslint.dylib        	       0x11d08066c i_slint_backend_selector::with_global_context::hb309b1de51ef7533 + 48 (lib.rs:157)
87  liblibrepcbslint.dylib        	       0x11d080498 i_slint_backend_selector::with_platform::h845b6e6159284220 + 36 (lib.rs:150)
88  liblibrepcbslint.dylib        	       0x11d081d8c slint_run_event_loop + 32 (lib.rs:60)
89  librepcb                      	       0x10489233c slint::run_event_loop(slint::EventLoopMode) + 40 (slint.h:367)
90  librepcb                      	       0x104892308 librepcb::editor::GuiApplication::exec() + 24 (guiapplication.cpp:836)
91  librepcb                      	       0x1046feca4 openWorkspace(librepcb::FilePath&) + 1104 (main.cpp:355)
92  librepcb                      	       0x1046fc304 runApplication() + 608 (main.cpp:236)
93  librepcb                      	       0x1046fb6f8 main + 1256 (main.cpp:129)
94  dyld                          	       0x190f1bf28 start + 2236

As far as I can see, it looks like the exception is somehow coming from slint_generated_appwindow_4.cpp which has the following content:

slint_generated_appwindow_4.cpp

I have recently updated to Slint 1.14, maybe it is related to that update but I am not sure. At least CI now fails way more often than before.

The test that triggers the failure is that one (using our wrapper around your ui-testing framework):

def test_click(librepcb, helpers):
    with librepcb.open() as app:
        # Open libraries panel
        app.get("SideBar::libraries-btn").click()

        # Wait until all libraries are fetched
        libs = app.get("LibrariesPanel::remote-libs #LibraryListViewItem *")
        libs.wait(REMOTE_LIBRARY_COUNT)

        # Check the last library, which also checks dependent library 0
        switches = libs.get("#Switch *")
        switches.wait_for(checked=[False, False, False])
        switches[2].click()
        switches.wait_for(checked=[True, False, True])

        # Deselect the first library, which also unchecks dependent library 2
        switches[0].click()
        switches.wait_for(checked=[False, False, False])

        # Check the second library, which also checks dependent library 0
        switches[1].click()  # <--- this crashes the application

        # ... further actions are not relevant

Basically the test just toggles a few UI switches by emulating mouse clicks.

Let me know if you need any assistance. Unfortunately I was not yet able to reproduce the crash in the debugger. Probably for that I'd require ui-testing to connect to an already running application, not sure if that is possible.

Reproducible Code (if applicable)

Environment Details

  • Slint Version: 1.14.0
  • Platform/OS: MacOS
  • Programming Language: C++
  • Backend/Renderer: Qt

Product Impact

Lots of CI failures

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:language-c++C++ API, codegen, CMake build system (mS,mO)need triagingIssue that the owner of the area still need to triage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions