setzer22 / egui_node_graph

Build your node graph applications in Rust, using egui
MIT License
715 stars 134 forks source link

Update to egui 0.17 #18

Closed Veykril closed 2 years ago

ada-x64 commented 2 years ago

This wasn't working for me, so I took the time to fix it.

backtrace ``` thread 'main' panicked at 'already immutably borrowed', C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\atomic_refcell-0.1.8\src\lib.rs:151:23 stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:498 1: core::panicking::panic_fmt at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\panicking.rs:116 2: core::panicking::panic_display at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\panicking.rs:72 3: atomic_refcell::AtomicRefCell::borrow_mut at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\atomic_refcell-0.1.8\src\lib.rs:151 4: epaint::mutex::rw_lock_impl::RwLock::write at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\epaint-0.17.0\src\mutex.rs:204 5: egui::context::Context::write at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-0.17.0\src\context.rs:170 6: egui::context::Context::frame_state at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-0.17.0\src\context.rs:474 7: egui::context::Context::available_rect at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-0.17.0\src\context.rs:436 8: egui::containers::panel::CentralPanel::show_dyn > at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-0.17.0\src\containers\panel.rs:688 9: egui::containers::panel::CentralPanel::show,egui_node_graph::editor_ui::impl$0::draw_graph_editor::closure$0> at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-0.17.0\src\containers\panel.rs:679 10: egui_node_graph::ui_state::GraphEditorState,enum$,enum$,egui_node_graph_examp at .\egui_node_graph\src\editor_ui.rs:86 11: egui_node_graph_example::app::impl$8::update at .\egui_node_graph_example\src\app.rs:363 12: egui_winit::epi::impl$1::update::closure$0 at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-winit-0.17.0\src\epi.rs:330 13: egui::context::Context::run at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-0.17.0\src\context.rs:198 14: egui_winit::epi::EpiIntegration::update at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui-winit-0.17.0\src\epi.rs:329 15: egui_glow::epi_backend::run::closure$1::closure$0 at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui_glow-0.17.0\src\epi_backend.rs:91 16: egui_glow::epi_backend::run::closure$1 at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\egui_glow-0.17.0\src\epi_backend.rs:135 17: winit::platform_impl::platform::event_loop::impl$2::run_return::closure$0 at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:206 18: alloc::boxed::impl$45::call_mut >,ref_mut$ > >,dyn$ at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:245 20: core::panic::unwind_safe::impl$23::call_once,winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0> at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\panic\unwind_safe.rs:271 21: std::panicking::try::do_call,tuple$<> > at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\std\src\panicking.rs:406 22: core::str::pattern::impl$26::into_searcher 23: std::panicking::try,core::panic::unwind_safe::AssertUnwindSafe > at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\std\src\panicking.rs:370 24: std::panic::catch_unwind,tuple$<> > at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\std\src\panic.rs:133 25: winit::platform_impl::platform::event_loop::runner::EventLoopRunner::catch_unwind,winit::platform_impl::platform::event_loop::runner::impl$3::call_event_hand at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:152 26: winit::platform_impl::platform::event_loop::runner::EventLoopRunner::call_event_handler at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:239 27: winit::platform_impl::platform::event_loop::runner::EventLoopRunner::call_redraw_events_cleared at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:404 28: winit::platform_impl::platform::event_loop::runner::EventLoopRunner::move_state_to at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:355 29: winit::platform_impl::platform::event_loop::runner::EventLoopRunner::redraw_events_cleared at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:231 30: winit::platform_impl::platform::event_loop::public_window_callback_inner::closure$0 at C:\Users\nyxma\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:944 31: core::ops::function::FnOnce::call_once > at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\ops\function.rs:227 32: core::panic::unwind_safe::impl$23::call_once at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\panic\unwind_safe.rs:271 33: std::panicking::try::do_call,isize> at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\std\src\panicking.rs:406 34: core::str::pattern::impl$26::into_searcher 35: std::panicking::try > at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\std\src\panicking.rs:370 36: std::panic::catch_unwind,isize> ```

Pretty simple fix. See the commit on my fork: https://github.com/ada-x64/egui_node_graph/commit/1b2756727239e8bd37fa17ce9aa421d5a78092bf

Basically, Context was being immutably borrowed twice because we had a reference to it in the mouse variable and were passing it to CentralPanel. Redeclaring it is cheap, so, might as well.

gmorenz commented 2 years ago

I created a 0.18 branch on top of this, PR #23

@ada-x64's change is also still necessary, except now it's a deadlock instead of a crash (and I reinvented the fix before reading these comments, oh well).

setzer22 commented 2 years ago

Thanks for the work! This was merged as part of gmorenz's 0.18 PR