dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

dioxus_desktop: Segfault when bundled on M1/macOS 14, seemingly due to MenuBar

Open benwr opened this issue 1 year ago • 4 comments

Problem

I'm building an app using dioxus (https://github.com/benwr/spartacus). The app runs fine via cargo run and dx serve. But as soon as it's bundled (either with dx bundle or cargo bundle, it segfaults on any click. This behavior goes away if I remove the with_menu() call from the app config. I've made a small repo that reproduces the issue for me here: https://github.com/benwr/segfaulty

This problem did not appear several months ago (even using an identical binary); I think it's likely new as of macOS 14.

Steps To Reproduce

Steps to reproduce the behavior:

  • Clone https://github.com/benwr/segfaulty on an m1 mac running sonoma
  • cargo run or dx serve --platform desktop to verify that you can click the resulting window with no segfault
  • dx bundle, and then open the resulting app bundle, and then click somewhere in the window.
  • Observe a crash

Expected behavior

The app shouldn't segfault when menus are present.

Screenshots

N/A

Environment:

  • Dioxus version: 0.4.3
  • Rust version: 1.72.0
  • OS info: macOS 14.2.1; m1
  • App platform: desktop

Questionnaire

  • [x] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [ ] I don't have time to fix this right now, but maybe later

benwr avatar Feb 09 '24 19:02 benwr

Here's an example stack trace from the crashed thread:

Thread 0 Crashed:: main Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib               	       0x1835a78f8 objc_retain + 16
1   AppKit                        	       0x187ffc030 -[NSMenuBarDisplayWindow _ensureReplicantWindows] + 104
2   AppKit                        	       0x187f0e350 __62-[NSMenuBarPresentationInstance _setBoundsAndUpdateResolution]_block_invoke + 736
3   AppKit                        	       0x187f1189c -[NSMenuBarPresentationInstance _forEachWindowDo:withBlock:] + 476
4   AppKit                        	       0x187f0e044 -[NSMenuBarPresentationInstance _setBoundsAndUpdateResolution] + 124
5   AppKit                        	       0x187f0e934 -[NSMenuBarPresentationInstance _showMenuBarWithAnimation:postingEvent:orderWindow:forAutoShow:noteVisibility:] + 168
6   AppKit                        	       0x187f12c04 +[NSMenuBarPresentationInstance _updateMenuBarObscured:] + 348
7   AppKit                        	       0x187f12a54 +[NSMenuBarPresentationInstance _setMenuBarObscured:] + 60
8   AppKit                        	       0x18737f920 -[NSApplication _handleActivatedEvent:] + 268
9   AppKit                        	       0x187a07aa4 -[NSApplication(NSEventRouting) sendEvent:] + 1780
10  segfaulty_dx                  	       0x104399af8 _$LT$$LP$A$C$$RP$$u20$as$u20$objc..message..MessageArguments$GT$::invoke::h62651d408d20bee0 + 104
11  segfaulty_dx                  	       0x10434aa38 objc::message::platform::send_super_unverified::_$u7b$$u7b$closure$u7d$$u7d$::h1583d4749d9ff243 + 56
12  segfaulty_dx                  	       0x104347c04 objc_exception::try::_$u7b$$u7b$closure$u7d$$u7d$::hd4008003626f536a + 44
13  segfaulty_dx                  	       0x104346214 objc_exception::try_no_ret::try_objc_execute_closure::h78c353097d27a3fd + 88
14  segfaulty_dx                  	       0x1043f2e80 RustObjCExceptionTryCatch + 36
15  segfaulty_dx                  	       0x104345dc8 objc_exception::try_no_ret::he3feaf054cdb5e85 + 188
16  segfaulty_dx                  	       0x104346a58 objc_exception::try::h62012ce71b1195fc + 72
17  segfaulty_dx                  	       0x104369534 objc::exception::try::h808d4f86f5bb5b52 + 12
18  segfaulty_dx                  	       0x10434a9c8 objc::message::platform::send_super_unverified::h939768392148ed4a + 172
19  segfaulty_dx                  	       0x10435ce9c tao::platform_impl::platform::app::send_event::h850079c911ba7475 + 504
20  AppKit                        	       0x187656908 -[NSApplication _handleEvent:] + 60
21  AppKit                        	       0x187221d74 -[NSApplication run] + 512
22  segfaulty_dx                  	       0x104296054 _$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$::invoke::hcf37e494338316ca + 64
23  segfaulty_dx                  	       0x1042a36e0 objc::message::platform::send_unverified::_$u7b$$u7b$closure$u7d$$u7d$::h1a51e9e08014a81b + 52
24  segfaulty_dx                  	       0x1042a1998 objc_exception::try::_$u7b$$u7b$closure$u7d$$u7d$::hbf4f9f50d0db5a99 + 44
25  segfaulty_dx                  	       0x10429f560 objc_exception::try_no_ret::try_objc_execute_closure::h00c7b716fe595113 + 76
26  segfaulty_dx                  	       0x1043f2e80 RustObjCExceptionTryCatch + 36
27  segfaulty_dx                  	       0x10429ee20 objc_exception::try_no_ret::hc3943bd1df1f1e0f + 168
28  segfaulty_dx                  	       0x1042a0454 objc_exception::try::h52626db86542a83c + 72
29  segfaulty_dx                  	       0x10429109c objc::exception::try::ha1f8bfbbf8f73ce4 + 12
30  segfaulty_dx                  	       0x1042a286c objc::message::platform::send_unverified::h4d34d4f83b016b2a + 136
31  segfaulty_dx                  	       0x104213000 tao::platform_impl::platform::event_loop::EventLoop$LT$T$GT$::run_return::h4a4f70efbc5e7c1a + 1100
32  segfaulty_dx                  	       0x104214014 tao::platform_impl::platform::event_loop::EventLoop$LT$T$GT$::run::h8749287936d75b3c + 20
33  segfaulty_dx                  	       0x1042128a4 tao::event_loop::EventLoop$LT$T$GT$::run::h9726b00f6815e640 + 60
34  segfaulty_dx                  	       0x10420baa8 dioxus_desktop::launch_with_props::h00bee03a74b35819 + 1136
35  segfaulty_dx                  	       0x10420b62c dioxus_desktop::launch_cfg::h7b04131e58eed6ad + 24
36  segfaulty_dx                  	       0x1041abcec segfaulty_dx::main::h4be4125a21f5784d + 44 (main.rs:26)
37  segfaulty_dx                  	       0x1041ab5f4 core::ops::function::FnOnce::call_once::h6af48b1c8acb8714 + 20 (function.rs:250)
38  segfaulty_dx                  	       0x1041aba68 std::sys_common::backtrace::__rust_begin_short_backtrace::h370f94f8937f19f8 + 24 (backtrace.rs:135)
39  segfaulty_dx                  	       0x1041ab840 std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hf0f860e19e24e98a + 28 (rt.rs:166)
40  segfaulty_dx                  	       0x1045d04c8 std::rt::lang_start_internal::hbbb9045627d56283 + 648
41  segfaulty_dx                  	       0x1041ab80c std::rt::lang_start::hfab517b8ac20787a + 84 (rt.rs:165)
42  segfaulty_dx                  	       0x1041abd20 main + 36
43  dyld                          	       0x1835f50e0 start + 2360

benwr avatar Feb 09 '24 19:02 benwr

The git version of dioxus uses muda for menu bars. This issue may already be fixed if you update dioxus. This could be a similar issue to https://github.com/tauri-apps/muda/issues/128 with the old menu system

ealmloff avatar Feb 09 '24 22:02 ealmloff

Is there any documentation on converting a 0.4 app to a 0.5 app? Or on the basics of using 0.5?

benwr avatar Feb 09 '24 22:02 benwr

Is there any documentation on converting a 0.4 app to a 0.5 app? Or on the basics of using 0.5?

https://github.com/DioxusLabs/docsite/pull/202 updates the docsite to 0.5. I haven't written a migration guide yet, but it is planned. Most of the doc examples currently compile. The main changes are:

  • use_future -> use_resource
  • use_state/use_ref -> use_signal
  • use_shared_state_provider -> use_context_provider(|| Signal::new())
  • use_shared_state<T> -> use_context::<Signal<T>>()
  • fermi atoms -> Signal::global
  • dependancies for signals are automatic in use_memo and use_resource for signals
  • Props always need to be PartialEq and Clone, you cannot borrow data in props

ealmloff avatar Feb 09 '24 22:02 ealmloff

Just confirmed this is fixed in 0.5, sucks that this issue persists in 0.4 but not much we can do.

jkelleyrtp avatar Mar 08 '24 22:03 jkelleyrtp