slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

C++: segfault on ComboBox initialization with an empty model #3704

Closed MiKom closed 1 year ago

MiKom commented 1 year ago

Steps to reproduce:

  1. Download slint cpp template (https://github.com/slint-ui/slint-cpp-template, I tried on rev 892aa00a0d06d73f80e551581805d2c421f294ab)
  2. Replace ui/appwindow.slint with:
    
    import { Button, ComboBox, VerticalBox } from "std-widgets.slint";

export global MySingleton { in property<[string]> my-model; } export component AppWindow inherits Window { in-out property counter: 42; callback request-increase-value(); VerticalBox { Text { text: "Counter: {root.counter}"; } ComboBox { model: MySingleton.my-model; } Button { text: "Increase value"; clicked => { root.request-increase-value(); } } } }


3. Compile and run the application

## Expected result

Application runs, combo box is empty

## Actual result

Application crashes on startup
tronical commented 1 year ago

First frames of the backtrace show a this null pointer:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x40)
  * frame #0: 0x0000000100044290 my_application`std::__1::vector<unsigned long, std::__1::allocator<unsigned long>>::begin[abi:v160006](this=0x0000000000000040 size=0) at vector:1423:30
    frame #1: 0x0000000100044161 my_application`slint::Model<slint::SharedString>::track_row_data_changes(this=0x0000000000000000, row=0) const at slint.h:407:49
    frame #2: 0x00000001000440c0 my_application`slint::Model<slint::SharedString>::row_data_tracked(this=0x0000000000000000, row=0) const at slint.h:418:9
    frame #3: 0x0000000100043f58 my_application`auto slint::private_api::access_array_index<std::__1::shared_ptr<slint::Model<slint::SharedString>>>(model=nullptr, index=0) at slint.h:345:31
    frame #4: 0x0000000100043f16 my_application`AppWindow::init(this=0x000060000029c330)::'lambda3'()::operator()() const at appwindow.h:1937:36
    frame #5: 0x0000000100043e91 my_application`void slint::private_api::Property<slint::SharedString>::set_binding<AppWindow::init(this=0x00007ff7bfefcd88, user_data=0x000060000029c330, value=0x00007f8e4a80a8c8)::'lambda3'()>(AppWindow::init(AppWindow const*, vtable::VWeak<slint::cbindgen_private::ComponentVTable, vtable::Dyn>, unsigned long, unsigned long)::'lambda3'()) const::'lambda'(void*, void*)::operator()(void*, void*) const at slint_properties.h:97:53
ogoffart commented 1 year ago

Thanks a lot for the bug report!