Skip to content
New issue

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

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

Already on GitHub? # to your account

[Crash] Resizing window at runtime #2041

Closed
teovoinea opened this issue Nov 13, 2021 · 8 comments
Closed

[Crash] Resizing window at runtime #2041

teovoinea opened this issue Nov 13, 2021 · 8 comments
Labels
bug does not behave the way it is supposed to shell/mac concerns the macOS backend

Comments

@teovoinea
Copy link

I have a single window application. It's a simple search box that starts off small, when the user hits enter, it expands.

I added a custom Controller to my TextBox that uses the EventCtx to modify the window size.

My exact code:

struct SearchBox;

impl<T, W: Widget<T>> Controller<T, W> for SearchBox {
    fn event(&mut self, child: &mut W, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
        if let Event::WindowConnected = event {
            ctx.request_focus();
        }

        if let Event::KeyDown(ke) = event  {
            if ke.key == Key::Enter {
                // TODO: search
                println!("Executing search...");

                ctx.window().set_size((680.0, 680.0));
            }
        }
        child.event(ctx, event, data, env)
    }
}

The crash output:

> cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/maybee-druid`
Executing search...
thread 'main' panicked at 'already borrowed: BorrowMutError', /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:513:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I have confirmed the line causing the crash is the set_size function.

Am I misusing this?

@jneem
Copy link
Collaborator

jneem commented Nov 14, 2021

No, that's definitely a bug. Could you get the backtrace?

@jneem jneem added the bug does not behave the way it is supposed to label Nov 14, 2021
@teovoinea
Copy link
Author

Sure thing, for additional context this is on macOS Big Sur 11.6

This is with RUST_BACKTRACE=full

thread 'main' panicked at 'already borrowed: BorrowMutError', /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:513:33
stack backtrace:
   0:        0x10b115021 - std::backtrace_rs::backtrace::libunwind::trace::h590dfebec4e77697
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:        0x10b115021 - std::backtrace_rs::backtrace::trace_unsynchronized::h99fbb54ac12f3b33
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10b115021 - std::sys_common::backtrace::_print_fmt::h98af9386233c17ac
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:67:5
   3:        0x10b115021 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::had87307b6abc1c9a
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:46:22
   4:        0x10b131c0b - core::fmt::write::hf956bc155d959fe3
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/fmt/mod.rs:1150:17
   5:        0x10b112aca - std::io::Write::write_fmt::h8329f2ae528d83ac
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/io/mod.rs:1667:15
   6:        0x10b1166b5 - std::sys_common::backtrace::_print::h6e4389a954583108
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:49:5
   7:        0x10b1166b5 - std::sys_common::backtrace::print::h8e088905fb2c3553
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:36:9
   8:        0x10b1166b5 - std::panicking::default_hook::{{closure}}::ha89bc0c5c4e06dc0
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:210:50
   9:        0x10b116297 - std::panicking::default_hook::hf75121343f052de7
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:227:9
  10:        0x10b116da0 - std::panicking::rust_panic_with_hook::h86c7505050d2207f
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:624:17
  11:        0x10b11683e - std::panicking::begin_panic_handler::{{closure}}::h61e80887dc228270
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:521:13
  12:        0x10b1154b7 - std::sys_common::backtrace::__rust_end_short_backtrace::hf0f0a63f6b510120
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:141:18
  13:        0x10b1167aa - rust_begin_unwind
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
  14:        0x10b13c87f - core::panicking::panic_fmt::hfb31ffade762ae98
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14
  15:        0x10b13c965 - core::result::unwrap_failed::hefa96ebaf26de4ba
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/result.rs:1617:5
  16:        0x10af7566b - core::result::Result<T,E>::expect::h2d1fca79cb220f59
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/result.rs:1259:23
  17:        0x10af239ca - core::cell::RefCell<T>::borrow_mut::h44de96a3bbb12369
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/cell.rs:940:9
  18:        0x10af5a5eb - druid::win_handler::AppState<T>::do_window_event::h1b493dda0eeedf13
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:513:22
  19:        0x10af5da32 - <druid::win_handler::DruidHandler<T> as druid_shell::window::WinHandler>::size::hf344c190fbf1b5d1
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:795:9
  20:        0x10b0506d9 - druid_shell::platform::mac::window::set_frame_size::hf33f9c52e661af18
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-shell-0.7.0/src/platform/mac/window.rs:489:9
  21:     0x7fff22cc71d9 - <unknown>
  22:     0x7fff22cd998b - <unknown>
  23:     0x7fff22cd9247 - <unknown>
  24:     0x7fff22cb5da6 - <unknown>
  25:     0x7fff22cd6d69 - <unknown>
  26:     0x7fff22cd4f69 - <unknown>
  27:        0x10b09bc05 - <(A,B) as objc::message::MessageArguments>::invoke::h53d8cece315a6ac1
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17
  28:        0x10b09aa41 - objc::message::platform::send_unverified::h36b443b9a2753df9
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9
  29:        0x10b05bb43 - objc::message::send_message::h0e86428927ce366c
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178:5
  30:        0x10b05bb43 - druid_shell::platform::mac::window::WindowHandle::set_size::hd3fffa5d2659a318
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-shell-0.7.0/src/platform/mac/window.rs:1042:22
  31:        0x10af1611c - druid_shell::window::WindowHandle::set_size::h86e3b67553341acb
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-shell-0.7.0/src/window.rs:212:9
  32:        0x10af35a49 - <maybee_druid::SearchBox as druid::widget::controller::Controller<T,W>>::event::h2fbafdefec518a8d
                               at /Users/teo/Not iCloud/Projects/maybee-druid/src/main.rs:98:17
  33:        0x10af6cba3 - <druid::widget::controller::ControllerHost<W,C> as druid::widget::widget::Widget<T>>::event::h0168f6eb8a88462e
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/widget/controller.rs:110:9
  34:        0x10af65624 - <alloc::boxed::Box<dyn druid::widget::widget::Widget<T>> as druid::widget::widget::Widget<T>>::event::hdf623c4943ad25ef
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/widget/widget.rs:239:9
  35:        0x10af0ca9c - druid::core::WidgetPod<T,W>::event::h3531fb0f26790e43
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/core.rs:787:13
  36:        0x10af26662 - <druid::widget::flex::Flex<T> as druid::widget::widget::Widget<T>>::event::h46bd17490e306336
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/widget/flex.rs:601:13
  37:        0x10af65624 - <alloc::boxed::Box<dyn druid::widget::widget::Widget<T>> as druid::widget::widget::Widget<T>>::event::hdf623c4943ad25ef
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/widget/widget.rs:239:9
  38:        0x10af0ca9c - druid::core::WidgetPod<T,W>::event::h3531fb0f26790e43
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/core.rs:787:13
  39:        0x10af25305 - <druid::widget::align::Align<T> as druid::widget::widget::Widget<T>>::event::h8a411352ac237789
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/widget/align.rs:81:9
  40:        0x10af65624 - <alloc::boxed::Box<dyn druid::widget::widget::Widget<T>> as druid::widget::widget::Widget<T>>::event::hdf623c4943ad25ef
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/widget/widget.rs:239:9
  41:        0x10af0ca9c - druid::core::WidgetPod<T,W>::event::h3531fb0f26790e43
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/core.rs:787:13
  42:        0x10af3042c - druid::window::Window<T>::event::h016f215ee793b1f5
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/window.rs:222:13
  43:        0x10af58058 - druid::win_handler::Inner<T>::do_window_event::hc6adf435864e8a0a
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:404:13
  44:        0x10af5a6b9 - druid::win_handler::AppState<T>::do_window_event::h1b493dda0eeedf13
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:513:22
  45:        0x10af5de44 - <druid::win_handler::DruidHandler<T> as druid_shell::window::WinHandler>::key_down::hef9c41782dc3d123
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/win_handler.rs:836:9
  46:        0x10b051a05 - druid_shell::platform::mac::window::key_down::h51bb6343f4bc8049
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-shell-0.7.0/src/platform/mac/window.rs:690:9
  47:     0x7fff22e0c578 - <unknown>
  48:     0x7fff22e0aa06 - <unknown>
  49:     0x7fff22e09881 - <unknown>
  50:     0x7fff230e1be1 - <unknown>
  51:     0x7fff22c71c8e - <unknown>
  52:        0x10b09f1c6 - <() as objc::message::MessageArguments>::invoke::h9f028b26906fa810
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17
  53:        0x10b09ed7c - objc::message::platform::send_unverified::hd9e498654ac5fbf6
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9
  54:        0x10b09540b - objc::message::send_message::h6100ace97749d3bf
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178:5
  55:        0x10b09540b - <*mut objc::runtime::Object as cocoa::appkit::NSApplication>::run::hd1d1b0caa3606ecd
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/cocoa-0.24.0/src/appkit.rs:438:9
  56:        0x10b075e96 - druid_shell::platform::mac::application::Application::run::h7e17644d2db8924d
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-shell-0.7.0/src/platform/mac/application.rs:74:13
  57:        0x10b0752f6 - druid_shell::application::Application::run::hf705d037434aa9ea
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-shell-0.7.0/src/application.rs:153:9
  58:        0x10af4068e - druid::app::AppLauncher<T>::launch::hc2a5986abbca6f23
                               at /Users/teo/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/druid-0.7.0/src/app.rs:183:9
  59:        0x10af154ef - maybee_druid::main::h47dcf3f2b602faf7
                               at /Users/teo/Not iCloud/Projects/maybee-druid/src/main.rs:39:5
  60:        0x10af439ee - core::ops::function::FnOnce::call_once::h02fb243e666fe364
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
  61:        0x10af24ec1 - std::sys_common::backtrace::__rust_begin_short_backtrace::h158a86a7ac03c991
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/sys_common/backtrace.rs:125:18
  62:        0x10af741e4 - std::rt::lang_start::{{closure}}::h8396f4e95ebfec87
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/rt.rs:63:18
  63:        0x10b1171ea - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h69c4046776cff27f
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:259:13
  64:        0x10b1171ea - std::panicking::try::do_call::hf29484cd182a8166
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:403:40
  65:        0x10b1171ea - std::panicking::try::h0dc079bc76330482
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:367:19
  66:        0x10b1171ea - std::panic::catch_unwind::hcdcc8b405dbc0e7c
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panic.rs:129:14
  67:        0x10b1171ea - std::rt::lang_start_internal::{{closure}}::hc519fd4fe9bea07d
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/rt.rs:45:48
  68:        0x10b1171ea - std::panicking::try::do_call::h47874b112ebb4df0
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:403:40
  69:        0x10b1171ea - std::panicking::try::h1bce813709a4c45c
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:367:19
  70:        0x10b1171ea - std::panic::catch_unwind::hfcbf753edbd8cf11
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panic.rs:129:14
  71:        0x10b1171ea - std::rt::lang_start_internal::hf65df31c3ffe3b9a
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/rt.rs:45:20
  72:        0x10af741ae - std::rt::lang_start::hd6c27fd9795ccc4a
                               at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/rt.rs:62:5
  73:        0x10af15ba6 - <unknown>
                               at /Users/teo/Projects/project/src/main.rs:12:21

@maan2003 maan2003 added the shell/mac concerns the macOS backend label Nov 16, 2021
@jneem
Copy link
Collaborator

jneem commented Nov 19, 2021

Hm, I'm having trouble understanding how this could happen on current master. Are you using an older version?

@teovoinea
Copy link
Author

I'm using the latest version from crates.io (0.7.0)

https://crates.io/crates/druid

I can try switching to master to see if that fixes it.

@jneem
Copy link
Collaborator

jneem commented Nov 22, 2021

Please try that. I think this is part of #1068, which should be fixed in master.

@teovoinea
Copy link
Author

Yup, I can confirm working from master fixes the issue. Thanks for the help, I appreciate it!

I see it's been a while since 0.7.0 was released, is there a reason you've been waiting?

@jneem
Copy link
Collaborator

jneem commented Dec 4, 2021

It isn't up to me :) I think mostly @cmyr has just been busy with non-druid things.

@kud1ing
Copy link
Contributor

kud1ing commented Dec 21, 2021

So this issue can be closed?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug does not behave the way it is supposed to shell/mac concerns the macOS backend
Projects
None yet
Development

No branches or pull requests

4 participants