Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with 'Recursion detected' on absolute-position #7402

Open
basdp opened this issue Jan 19, 2025 · 3 comments
Open

Crash with 'Recursion detected' on absolute-position #7402

basdp opened this issue Jan 19, 2025 · 3 comments
Labels
a:live preview The Live preview of slintpad or the LSP (mT,bO) bug Something isn't working need triaging Issue that the owner of the area still need to triage

Comments

@basdp
Copy link

basdp commented Jan 19, 2025

Bug Description

In the provided Slint code, the program crashes when trying to read the absolute-position in the init block of a Rectangle (but issue is not limited to the Rectangle only). The specific line that causes the crash is:

port.y = self.absolute-position.y;

This assignment is done within a Rectangle component that is part of a larger layout. However, the absolute-position is not accessible or valid in this context at the time of the assignment, which leads to the crash. The expectation is that absolute-position should be available and usable in this situation, but it appears to be causing the program to crash instead. Or, in the very least, should not crash the program with a Recursion detected.

Reproducible Code

struct Port {
    x: length,
    y: length,
    name: string,
}

component Node inherits Rectangle {
    in-out property <[Port]> ports;
    private property <Port> port: ports[0];

    width: 100px;
    height: 100px;

    VerticalLayout {
        HorizontalLayout {
            Text {
                text: port.name;
            }
        }

        Rectangle {
            background: #f8e45c;
            min-width: 15px;
            height: 20px;

            init => {
                // This line crashes
                port.y = self.absolute-position.y;
            }
        }
    }
}

export component Demo inherits Window {
    background: #242424;
    min-width: 800px;
    min-height: 400px;

    Node {
        ports: [
            { name: "Port1" },
        ];
    }
}

Link to Slintpad with this code: https://slintpad.com/?load_url=https%3A%2F%2Fgist.github.com%2Fbasdp%2F90196efdc11d4e0d82117df9051f6371

Upon further inspection, I found out this also crashes:

export component Demo {
    Rectangle {
        init => {
            // This line crashes
            debug(self.absolute-position.y);
        }
    }
}

Slintpad: https://slintpad.com/?load_url=https%3A%2F%2Fgist.github.com%2Fbasdp%2F69a55227c846fdaaa85222e57dc495bd

Not entirely sure it's related, but at least it's another absolute-position in an init that crashes.

For what it's worth, this also crashes:

...
changed absolute-position => {
    debug(self.absolute-position);
}
...

Note: the above (changed absolute-position) code even crashes when the callback is empty (e.g. comment out the debug line). Again, not sure if this is the same issue, or if it is a separate one.

Hypothesis

I suspect it is not intended to read absolute-position from init, as the init callback is being called inside-out (ref: https://docs.slint.dev/latest/docs/slint/reference/common/#init). Maybe the layout pass hasn't decided its absolute position yet. If this is not intended to be called from init, what other options do we have to do something similar? Also, I think no Slint code should crash, so this is a bug nonetheless (?).

Environment Details

  • Slint Version: tested myself on v1.9.2, but others have mentioned this as early as 1.6.0
  • Platform/OS: Windows and MacOS
  • Programming Language: Slint
  • Backend/Renderer: any

Product Impact

I am making a node based editor, similar to what has been discussed here: #5248

Note, that this issue has been discussed there as crashing too. I just made a minimal example that might be easier to track.

@basdp basdp added bug Something isn't working need triaging Issue that the owner of the area still need to triage labels Jan 19, 2025
@basdp basdp changed the title Crash with 'Recursion detected' on absolute-position in dynamically created element's init Crash with 'Recursion detected' on absolute-position Jan 20, 2025
@basdp
Copy link
Author

basdp commented Jan 21, 2025

Looks like even mentioning absolute-position in an Slint file breaks the compiler even:

PS C:\dev\xxx> $env:RUST_BACKTRACE='full'
PS C:\dev\xxx> cargo build               
   Compiling xxx v0.1.0 (C:\dev\xxx\xxx)
error: failed to run custom build command for `xxx v0.1.0 (C:\dev\xxx\xxx)`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `C:\dev\xxx\target\debug\build\xxx-44714ffeaf20b1c6\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at C:\Users\basdu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-1.9.2\llr\expression.rs:692:89:
  called `Option::unwrap()` on a `None` value
  stack backtrace:
     0:     0x7ff79dad30ed - std::backtrace_rs::backtrace::dbghelp64::trace
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
     1:     0x7ff79dad30ed - std::backtrace_rs::backtrace::trace_unsynchronized
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
     2:     0x7ff79dad30ed - std::sys::backtrace::_print_fmt
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:65
     3:     0x7ff79dad30ed - std::sys::backtrace::impl$0::print::impl$0::fmt
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:40
     4:     0x7ff79daeb6e9 - core::fmt::rt::Argument::fmt
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\fmt\rt.rs:173 
     5:     0x7ff79daeb6e9 - core::fmt::write
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\fmt\mod.rs:1182
     6:     0x7ff79dacf3b1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\io\mod.rs:1827 
     7:     0x7ff79dad4e97 - std::panicking::default_hook::closure$1
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:269
     8:     0x7ff79dad4a89 - std::panicking::default_hook
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:296
     9:     0x7ff79dad55d2 - std::panicking::rust_panic_with_hook
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:800
    10:     0x7ff79dad53df - std::panicking::begin_panic_handler::closure$0
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:667
    11:     0x7ff79dad37df - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:168
    12:     0x7ff79dad4ff6 - std::panicking::begin_panic_handler
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665
    13:     0x7ff79daf61a4 - core::panicking::panic_fmt
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:74
    14:     0x7ff79daf624d - core::panicking::panic
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:148
    15:     0x7ff79daf610e - core::option::unwrap_failed
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\option.rs:2020
    16:     0x7ff79cd88138 - <i_slint_compiler::llr::expression::EvaluationContext<T> as i_slint_compiler::llr::expression::TypeResolutionContext>::property_ty::h4a675fc902a399f4
    17:     0x7ff79d123fe2 - i_slint_compiler::generator::rust::global_inner_name::h329feba7db526c53
    18:     0x7ff79d1018f8 - i_slint_compiler::generator::rust::generate_sub_component::{{closure}}::h5ecbc035c4c57f1d
    19:     0x7ff79cd64256 - core::iter::adapters::map::map_fold::{{closure}}::h0fd848dfff54ba8d
    20:     0x7ff79d0d3ed2 - <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::enumerate::{{closure}}::h0eba0bad0a4d100e
    21:     0x7ff79cef1580 - <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold::hea2cf1ff544989ae
    22:     0x7ff79d0d3ea7 - <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::hb5791f83dbac649d
    23:     0x7ff79cd47410 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h0c11c8fd1e05f051
    24:     0x7ff79cd5e718 - core::iter::traits::iterator::Iterator::for_each::hb5fbf7ad1e28a7ea
    25:     0x7ff79cec92f5 - alloc::vec::Vec<T,A>::extend_trusted::hcb3598c27bbdc456
    26:     0x7ff79cee0819 - <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::h09fdf011e1dbd0b3
    27:     0x7ff79cedd2f2 - <alloc::vec::Vec<T,A> as core::iter::traits::collect::Extend<T>>::extend::hfcded72cba8e81f1
    28:     0x7ff79d0f0449 - i_slint_compiler::generator::rust::public_api::{{closure}}::hb176f60158c927c3
    29:     0x7ff79d109e7b - i_slint_compiler::generator::rust::generate_global::{{closure}}::h27f46006025a0a7a    
    30:     0x7ff79d114918 - i_slint_compiler::generator::rust::generate_item_tree::{{closure}}::h19d21e32f9769ec7 
    31:     0x7ff79d0fb193 - i_slint_compiler::generator::rust::public_api::{{closure}}::hb176f60158c927c3
    32:     0x7ff79d0e0dd3 - i_slint_compiler::generator::rust::generate::{{closure}}::he9c03776ff6a0deb
    33:     0x7ff79cd65b83 - core::iter::adapters::map::map_fold::{{closure}}::h45c093c3bfa1531f
    34:     0x7ff79ceec824 - <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold::h6f438b0071e76f15
    35:     0x7ff79cd49bfe - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::hd81b634dbfda6d55
    36:     0x7ff79cd5e4d8 - core::iter::traits::iterator::Iterator::for_each::h9909fc0b5109d1cf
    37:     0x7ff79cec8844 - alloc::vec::Vec<T,A>::extend_trusted::hb3f4b4260d4bc439
    38:     0x7ff79cee0989 - <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend::h37437687740df8af
    39:     0x7ff79ceb43ae - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h515a48ce1002e5a6
    40:     0x7ff79cee1251 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::h088d4aa3aa7f65ef
    41:     0x7ff79ceddfb7 - <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter::h083a9a189a8db3ee
    42:     0x7ff79cd5c271 - core::iter::traits::iterator::Iterator::collect::he494cb2d987b0123
    43:     0x7ff79d0dea3c - i_slint_compiler::generator::rust::generate::hd95f44ba0ac4ddc4
    44:     0x7ff79cbed8ad - slint_build::compile_with_config::{{closure}}::h5ed359d54bff9447
    45:     0x7ff79cbece24 - slint_build::compile_with_config::hca6c68ec86fc26ef
    46:     0x7ff79cc1146b - core::cmp::impls::<impl core::cmp::PartialEq for char>::eq::h148c781504b03661
    47:     0x7ff79cc34b46 - core::ops::function::FnOnce::call_once::hfad0e2491a9c47fe
    48:     0x7ff79cc3b219 - std::sys::backtrace::__rust_begin_short_backtrace::haced0209bf990842
    49:     0x7ff79cbfa7bc - std::rt::lang_start::{{closure}}::h5429ddebf42b2ad5
    50:     0x7ff79dac87a9 - std::rt::lang_start_internal::closure$2
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\rt.rs:141      
    51:     0x7ff79dac87a9 - std::panicking::try::do_call
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:557
    52:     0x7ff79dac87a9 - std::panicking::try
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:521
    53:     0x7ff79dac87a9 - std::panic::catch_unwind
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panic.rs:350   
    54:     0x7ff79dac87a9 - std::rt::lang_start_internal
                                 at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\rt.rs:141      
    55:     0x7ff79cbfa797 - std::rt::lang_start::h6b0808a014ac1b80
    56:     0x7ff79cc114d9 - main
    57:     0x7ff79daf2920 - invoke_main
                                 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    58:     0x7ff79daf2920 - __scrt_common_main_seh
                                 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288        
    59:     0x7fff5694259d - BaseThreadInitThunk
    60:     0x7fff58a0af38 - RtlUserThreadStart

@ogoffart
Copy link
Member

Thanks for the detailed bug report.
The compiler crash because of changed absolute-position callback should be fixed by #7391

Regarding the Recursion detected panic, the problem, i think, this is related to how the LivePreview instantiate the component, and if the component queries the absolute-position during the instentiation, it recurses.

@ogoffart ogoffart added the a:live preview The Live preview of slintpad or the LSP (mT,bO) label Jan 21, 2025
@basdp
Copy link
Author

basdp commented Jan 21, 2025

Thanks for the time to take a look at it. Makes sense about the compiler crash being fixed with the not-yet-materialized fix.

The Recursion detected is also in compiled code by the way, not only in the LivePreview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:live preview The Live preview of slintpad or the LSP (mT,bO) bug Something isn't working need triaging Issue that the owner of the area still need to triage
Projects
None yet
Development

No branches or pull requests

2 participants