Originally posted by **Tastaturtaste** June 23, 2023
I am currently checking out slint and tried to write a simple lights-out game. The slint GUI code seems to be fine, because the "Show Preview" inline button in vscode opens the window as expected and it [also works in SlintPad](https://slint.dev/releases/1.0.2/editor/?snippet=component+Tile+inherits+Rectangle+%7B%0A++++background%3A+Colors.grey%3B%0A++++out+property+%3Cbool%3E+activated%3A+false%3B%0A++++in+property+%3Cbool%3E+lit-up%3A+false%3B%0A++++callback+notify_clicked%3B%0A++++TouchArea%7B%0A++++++++clicked+%3D%3E+%7B+activated+%3D+%21activated%3B+notify-clicked%28%29%3B+%7D%0A++++%7D%0A++++inner+%3A%3D+Rectangle+%7B%0A++++++++width%3A+50%25%3B%0A++++++++height%3A+50%25%3B%0A++++++++background%3A+lit-up+%3F+Colors.cyan+%3A+Colors.darkcyan%3B%0A++++%7D%0A%7D%0A%0Acomponent+ButtonField+inherits+Rectangle%7B%0A++++in-out+property+%3Cint%3E+size%3A+3%3B%0A++++private+property+%3Cpercent%3E+pad_pct%3A+5%25%3B%0A++++private+property+%3Clength%3E+pad_width%3A+pad_pct+*+self.width%3B%0A++++private+property+%3Clength%3E+pad_height%3A+pad_pct+*+self.height%3B%0A++++private+property+%3Clength%3E+button_width%3A+%28%281+-+%28size+%2B+1%29+*+pad_pct%29+%2F+size%29+*+self.width%3B%0A++++private+property+%3Clength%3E+button_height%3A+%28%281+-+%28size+%2B+1%29+*+pad_pct%29+%2F+size%29+*+self.height%3B%0A++++callback+notify_clicked%28int%2C+int%29%3B%0A++++for+tile%5Bidx%5D+in+%28size*size%29%3A+Tile%7B%0A++++++++width%3A+button_width%3B%0A++++++++height%3A+button_height%3B%0A++++++++x%3A+pad_width+%2B+mod%28idx%2C+size%29+*+%28self.width+%2B+pad_width%29%3B%0A++++++++y%3A+pad_height+%2B+floor%28idx+%2F+size%29+*+%28self.height+%2B+pad_height%29%3B%0A++++++++notify_clicked+%3D%3E+%7B+parent.notify_clicked%28mod%28idx%2Csize%29%2C+floor%28idx+%2F+size%29%29+%7D%0A++++%7D%0A%0A%7D%0A%0Aexport+component+Example+inherits+Window+%7B%0A++++preferred-width%3A+340px%3B%0A++++preferred-height%3A+340px%3B%0A++++callback+notify_clicked%28int%2C+int%29%3B%0A++++ButtonField+%7B%0A++++++++background%3A+Colors.black%3B%0A++++++++notify_clicked%28x%2Cy%29+%3D%3E+%7Bparent.notify-clicked%28x%2Cy%29%7D%0A++++%7D%0A%7D).
The build.rs was automatically generated by the cargo-generate command and the slint project template. Its contents are:
```rust
fn main() {
slint_build::compile("ui/appwindow.slint").unwrap();
}
```
The complete error message with RUST_BACKTRACE=1 is as follows:
Error Message
```
Compiling lights-out v0.1.0 (I:\dev\lights-out)
error: failed to run custom build command for `lights-out v0.1.0 (I:\dev\lights-out)`
Caused by:
process didn't exit successfully: `I:\dev\lights-out\target\debug\build\lights-out-fca21e9d9512d328\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:690:71
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:578
1: core::panicking::panic_fmt
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:67
2: core::panicking::panic
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:117
3: enum2$ >::unwrap
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\option.rs:950
4: i_slint_compiler::generator::rust::generate_sub_component
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:690
5: i_slint_compiler::generator::rust::generate_item_tree
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:1242
6: i_slint_compiler::generator::rust::generate_repeated_component
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:1478
7: i_slint_compiler::generator::rust::generate_sub_component
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:743
8: i_slint_compiler::generator::rust::generate::closure$1
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:163
9: core::iter::adapters::map::map_fold::closure$0 >,proc_macro2::TokenStream,tuple$<>,i_slint_compiler::generator::rust::generate::closure_env$1,core::iter::traits::iterator::Iterator::for_ea
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\iter\adapters\map.rs:84
10: core::iter::traits::iterator::Iterator::fold >,tuple$<>,core::iter::adapters::map::map_fold::closure_env$0 >,i_slint_compiler::generator::rust::generate::closure_env$1,tuple$<>,core::iter::traits::iterator::Iter
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\iter\adapters\map.rs:124
12: core::iter::traits::iterator::Iterator::for_each >,i_slint_compiler::generator::rust::generate::closure_env$1>,alloc::vec::impl$20::extend
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\iter\traits\iterator.rs:857
13: alloc::vec::Vec::extend_trusted >,i_slint_com
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\mod.rs:2844
14: alloc::vec::spec_extend::impl$1::spec_extend >,i_slint_compiler::generator::rust::generate::closure_env$1>,alloc:
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\spec_extend.rs:26
15: alloc::vec::spec_from_iter_nested::impl$1::from_iter >,i_slint_compiler::generator::rust::generate::closure_env$1
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\spec_from_iter_nested.rs:62
16: alloc::vec::spec_from_iter::impl$0::from_iter >,i_slint_compiler::generator::rust::generate::closure_env$1> >
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\spec_from_iter.rs:33
17: alloc::vec::impl$15::from_iter >,i_slint_compiler::generator::rust::generate::closure_env$1> >
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\mod.rs:2712
18: core::iter::traits::iterator::Iterator::collect >,i_slint_compiler::generator::rust::generate::closure_env$1>,alloc::vec::Vec >
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-build-1.0.2\lib.rs:338
21: slint_build::compile >
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-build-1.0.2\lib.rs:272
22: build_script_build::main
at .\build.rs:2
23: core::ops::function::FnOnce::call_once >
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
Any help would be appreciated.
Edit:
I use `slint_build 1.0.2` with rust 1.70 on Windows.
The culprit in this case was the model expression in the for loop. Replacing size*size by N and defining N as a property resolves the issue. But I do think such expressions should be allowed or at least provide a clear error message.
Discussed in https://github.com/slint-ui/slint/discussions/2971
Error Message
``` Compiling lights-out v0.1.0 (I:\dev\lights-out) error: failed to run custom build command for `lights-out v0.1.0 (I:\dev\lights-out)` Caused by: process didn't exit successfully: `I:\dev\lights-out\target\debug\build\lights-out-fca21e9d9512d328\build-script-build` (exit code: 101) --- stderr thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:690:71 stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:578 1: core::panicking::panic_fmt at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:67 2: core::panicking::panic at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:117 3: enum2$ >::unwrap
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\option.rs:950
4: i_slint_compiler::generator::rust::generate_sub_component
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:690
5: i_slint_compiler::generator::rust::generate_item_tree
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:1242
6: i_slint_compiler::generator::rust::generate_repeated_component
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:1478
7: i_slint_compiler::generator::rust::generate_sub_component
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:743
8: i_slint_compiler::generator::rust::generate::closure$1
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.0.2\generator\rust.rs:163
9: core::iter::adapters::map::map_fold::closure$0 >,proc_macro2::TokenStream,tuple$<>,i_slint_compiler::generator::rust::generate::closure_env$1,core::iter::traits::iterator::Iterator::for_ea
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\iter\adapters\map.rs:84
10: core::iter::traits::iterator::Iterator::fold >,tuple$<>,core::iter::adapters::map::map_fold::closure_env$0 >,i_slint_compiler::generator::rust::generate::closure_env$1,tuple$<>,core::iter::traits::iterator::Iter
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\iter\adapters\map.rs:124
12: core::iter::traits::iterator::Iterator::for_each >,i_slint_compiler::generator::rust::generate::closure_env$1>,alloc::vec::impl$20::extend
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\iter\traits\iterator.rs:857
13: alloc::vec::Vec::extend_trusted >,i_slint_com
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\mod.rs:2844
14: alloc::vec::spec_extend::impl$1::spec_extend >,i_slint_compiler::generator::rust::generate::closure_env$1>,alloc:
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\spec_extend.rs:26
15: alloc::vec::spec_from_iter_nested::impl$1::from_iter >,i_slint_compiler::generator::rust::generate::closure_env$1
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\spec_from_iter_nested.rs:62
16: alloc::vec::spec_from_iter::impl$0::from_iter >,i_slint_compiler::generator::rust::generate::closure_env$1> >
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\spec_from_iter.rs:33
17: alloc::vec::impl$15::from_iter >,i_slint_compiler::generator::rust::generate::closure_env$1> >
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\alloc\src\vec\mod.rs:2712
18: core::iter::traits::iterator::Iterator::collect >,i_slint_compiler::generator::rust::generate::closure_env$1>,alloc::vec::Vec >
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-build-1.0.2\lib.rs:338
21: slint_build::compile >
at C:\Users\joshu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\slint-build-1.0.2\lib.rs:272
22: build_script_build::main
at .\build.rs:2
23: core::ops::function::FnOnce::call_once >
at /rustc/90c541806f23a127002de5b4038be731ba1458ca\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
The culprit in this case was the
model
expression in the for loop. Replacingsize*size
byN
and defining N as a property resolves the issue. But I do think such expressions should be allowed or at least provide a clear error message.