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

Ui::with_layer_id panics when given LayerId is different from the Ui's current one. #5178

Closed
Adanos020 opened this issue Sep 27, 2024 · 9 comments · Fixed by #5191
Closed
Assignees
Labels
bug Something is broken

Comments

@Adanos020
Copy link
Contributor

Describe the bug
Title says it all. This renders the function utterly useless.

To Reproduce
Simply run this code and observe it panic straight away. The only dependency here is eframe 0.29.0. The issue still persists on master at the time of writing.

use eframe::egui::{CentralPanel, Id, LayerId, Order};
use eframe::NativeOptions;

fn main() -> eframe::Result<()> {
    eframe::run_simple_native("test", NativeOptions::default(), |ctx, _frame| {
        CentralPanel::default().show(ctx, |ui| {
            ui.with_layer_id(LayerId::new(Order::Tooltip, Id::new("tooltip")), |ui| {
                //
            });
        });
    })
}

Callstack:

thread 'main' panicked at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/widget_rect.rs:142:17:
Widget changed layer_id during the frame
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
   2: egui::widget_rect::WidgetRects::insert
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/widget_rect.rs:142:17
   3: egui::context::Context::create_widget::{{closure}}
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/context.rs:1146:13
   4: egui::context::Context::write
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/context.rs:763:9
   5: egui::context::Context::create_widget
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/context.rs:1140:9
   6: egui::ui::Ui::remember_min_rect
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/ui.rs:1068:9
   7: egui::ui::Ui::scope_dyn
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/ui.rs:2257:24
   8: egui::ui::Ui::scope
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/ui.rs:2235:9
   9: egui::ui::Ui::with_layer_id
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/ui.rs:2268:9
  10: egui_test::main::{{closure}}::{{closure}}
             at ./src/main.rs:7:13
  11: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  12: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  13: egui::containers::panel::CentralPanel::show_inside_dyn::{{closure}}
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/containers/panel.rs:1118:13
  14: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  15: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  16: egui::containers::frame::Frame::show_dyn
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/containers/frame.rs:283:19
  17: egui::containers::frame::Frame::show
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/containers/frame.rs:273:9
  18: egui::containers::panel::CentralPanel::show_inside_dyn
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/containers/panel.rs:1116:9
  19: egui::containers::panel::CentralPanel::show_dyn
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/containers/panel.rs:1149:30
  20: egui::containers::panel::CentralPanel::show
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/containers/panel.rs:1128:9
  21: egui_test::main::{{closure}}
             at ./src/main.rs:6:9
  22: <eframe::run_simple_native::SimpleApp<U> as eframe::epi::App>::update
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/lib.rs:319:13
  23: eframe::native::epi_integration::EpiIntegration::update::{{closure}}
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/epi_integration.rs:283:17
  24: egui::context::Context::run
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/egui/src/context.rs:815:13
  25: eframe::native::epi_integration::EpiIntegration::update
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/epi_integration.rs:276:27
  26: eframe::native::glow_integration::GlowWinitRunning::run_ui_and_paint
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/glow_integration.rs:595:13
  27: <eframe::native::glow_integration::GlowWinitApp as eframe::native::winit_integration::WinitApp>::run_ui_and_paint
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/glow_integration.rs:389:13
  28: <eframe::native::run::WinitAppWrapper<T> as winit::application::ApplicationHandler<eframe::native::winit_integration::UserEvent>>::window_event::{{closure}}
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:283:21
  29: eframe::native::event_loop_context::with_event_loop_context
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/event_loop_context.rs:53:5
  30: <eframe::native::run::WinitAppWrapper<T> as winit::application::ApplicationHandler<eframe::native::winit_integration::UserEvent>>::window_event
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:280:9
  31: winit::event_loop::dispatch_event_for_app
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/event_loop.rs:642:52
  32: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand::{{closure}}
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform/run_on_demand.rs:76:13
  33: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:294:13
  34: winit::platform_impl::linux::x11::EventLoop<T>::single_iteration
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/mod.rs:563:17
  35: winit::platform_impl::linux::x11::EventLoop<T>::pump_events
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/mod.rs:418:13
  36: winit::platform_impl::linux::x11::EventLoop<T>::run_on_demand
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/mod.rs:385:19
  37: winit::platform_impl::linux::EventLoop<T>::run_on_demand
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/mod.rs:813:56
  38: <winit::event_loop::EventLoop<T> as winit::platform::run_on_demand::EventLoopExtRunOnDemand>::run_on_demand
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform/run_on_demand.rs:89:9
  39: winit::platform::run_on_demand::EventLoopExtRunOnDemand::run_app_on_demand
             at /home/anghosh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform/run_on_demand.rs:75:9
  40: eframe::native::run::run_and_return
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:300:5
  41: eframe::native::run::run_glow::{{closure}}
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:332:13
  42: eframe::native::run::with_event_loop::{{closure}}
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:52:12
  43: std::thread::local::LocalKey<T>::try_with
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:283:12
  44: std::thread::local::LocalKey<T>::with
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:260:9
  45: eframe::native::run::with_event_loop
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:42:5
  46: eframe::native::run::run_glow
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/native/run.rs:330:16
  47: eframe::run_native
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/lib.rs:259:13
  48: eframe::run_simple_native
             at /home/anghosh/.cargo/git/checkouts/egui-5e4507fa4153be06/59d7183/crates/eframe/src/lib.rs:323:5
  49: egui_test::main
             at ./src/main.rs:5:5
  50: core::ops::function::FnOnce::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Expected behavior
The application should not panic, and the new Ui should have the given LayerId as intended.

@Adanos020 Adanos020 added the bug Something is broken label Sep 27, 2024
@shadowbrok3r
Copy link

@Adanos020 Have you found any workarounds? I have a number of places I'm using ui.with_layer_id() and have not seemed to find any workarounds for yet

@Adanos020
Copy link
Contributor Author

Adanos020 commented Sep 28, 2024

@shadowbrok3r Unfortunately not. I'm hoping this will get resolved soon, as it breaks egui_dock and I can't release 0.14 in this state.

@shadowbrok3r
Copy link

@Adanos020 Ah I didn't realize I was talking to the creator of egui_dock, the code with ui.with_layer_id() that I was actually referring to was the egui_dock crate that I forked and was trying to solve the layer id issue myself, so I guess if i end up finding a solution I will let you know!

@Adanos020
Copy link
Contributor Author

@shadowbrok3r That would be grand, thanks. To be fair the whole egui_dock needs a rewrite, as it's becoming harder and harder to maintain it the more it grows. One thing I'm considering is replacing our drag-n-drop system with the dedicated egui API, which should eliminate the need for with_layer_id.

@rustbasic
Copy link
Contributor

rustbasic commented Sep 29, 2024

Note: I ran the above example on Windows 10 (glow, wgpu) without any problems.

@shadowbrok3r
Copy link

Note: I ran the above example on Windows 10 (glow, wgpu) without any problems.

Interesting, I'm having the issue in both Wasm and Arch Linux

@Adanos020
Copy link
Contributor Author

I'm also on Arch Linux.

@emilk emilk added this to the Next Patch Release milestone Sep 30, 2024
@emilk
Copy link
Owner

emilk commented Sep 30, 2024

Note that this is a debug_assert, so you'll only see it in debug builds.

@emilk emilk self-assigned this Sep 30, 2024
@emilk
Copy link
Owner

emilk commented Sep 30, 2024

The problem was introduced in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants