rfd
rfd copied to clipboard
`FileDialog::pick_file` window does not appear on egui-miniquad in MacOS
I'm using miniquad for graphics together with egui, plus the glue crate egui-miniquad. I've been using rfd
to open a file dialog window with FileDialog::pick_file
and it works perfectly on Linux, but when I tried this on MacOS the dialog window does not open. The program does not crash, the method returns None
and I get this dump on the terminal:
ThreadId(1)
ThreadId(1)
dialog created
2023-03-13 19:15:10.540 minimal[2866:1683315] Suppressing invocation of -[NSApplication runModalForWindow:]. -[NSApplication runModalForWindow:] cannot run inside a transaction begin/commit pair, or inside a transaction commit. Consider switching to an asynchronous equivalent.
(
0 AppKit 0x000000019f0b5f30 -[NSApplication runModalForWindow:] + 332
1 AppKit 0x000000019f7cd27c -[NSSavePanel runModal] + 340
2 minimal 0x000000010497c65c _ZN60_$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17hca4b21535b63891fE + 76
3 minimal 0x0000000104979eb0 _ZN4objc7message8platform15send_unverified17h7c4f4a7a561816f1E + 132
4 minimal 0x000000010497ab9c _ZN3rfd7backend5macos11file_dialog9panel_ffi5Panel9run_modal17h60490bfffe7621fdE + 276
5 minimal 0x0000000104978f8c _ZN3rfd7backend5macos11file_dialog93_$LT$impl$u20$rfd..backend..FilePickerDialogImpl$u20$for$u20$rfd..file_dialog..FileDialog$GT$9pick_file28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17h2f07129970620fb5E + 68
6 minimal 0x000000010497e190 _ZN3rfd7backend5macos5utils11run_on_main17h52fe56e75e678909E + 140
7 minimal 0x0000000104978f3c _ZN3rfd7backend5macos11file_dialog93_$LT$impl$u20$rfd..backend..FilePickerDialogImpl$u20$for$u20$rfd..file_dialog..FileDialog$GT$9pick_file28_$u7b$$u7b$closure$u7d$$u7d$17h68656d055d7a4c95E + 52
8 minimal 0x0000000104980054 _ZN4objc2rc11autorelease15autoreleasepool17hbf73ca4fcf4c8cccE + 120
9 minimal 0x000000010497c9f0 _ZN3rfd7backend5macos11file_dialog93_$LT$impl$u20$rfd..backend..FilePickerDialogImpl$u20$for$u20$rfd..file_dialog..FileDialog$GT$9pick_file17h79ee5c60c420eef9E + 52
10 minimal 0x000000010497e318 _ZN3rfd11file_dialog10FileDialog9pick_file17h82fb10336bc5c55dE + 52
11 minimal 0x00000001048f29a4 _ZN64_$LT$minimal..Stage$u20$as$u20$miniquad..event..EventHandler$GT$4draw28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17ha4f20f72bebcfc13E + 424
12 minimal 0x00000001048eda10 _ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h268b172a56bea86fE + 28
13 minimal 0x0000000104b8ce40 _ZN90_$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$9call_once17h87c5bddd8af751a4E + 56
14 minimal 0x00000001049a5e18 _ZN4egui10containers6window6Window8show_dyn28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17ha8cf3ba7b3e72e40E + 180
15 minimal 0x00000001049ca4b0 _ZN4egui10containers6resize6Resize4show17hbc7c59db1f30a236E + 152
16 minimal 0x00000001049a5d10 _ZN4egui10containers6window6Window8show_dyn28_$u7b$$u7b$closure$u7d$$u7d$17hfbfce2a55cfebcf9E + 124
17 minimal 0x00000001049bf81c _ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h11d154a31e1290aaE + 32
18 minimal 0x0000000104b8ce40 _ZN90_$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$9call_once17h87c5bddd8af751a4E + 56
19 minimal 0x0000000104b8303c _ZN4egui2ui2Ui9scope_dyn17h62458a0f51e08f85E + 240
20 minimal 0x0000000104a5349c _ZN4egui2ui2Ui5scope17ha651e514318de1c9E + 244
21 minimal 0x000000010499f1f8 _ZN4egui10containers17collapsing_header15CollapsingState20show_body_unindented17h4492200153b158afE + 300
22 minimal 0x00000001049a5280 _ZN4egui10containers6window6Window8show_dyn17h9614bbc0855f6bb3E + 2216
23 minimal 0x00000001048ee654 _ZN4egui10containers6window6Window4show17ha3ff1502e8bb6af6E + 208
24 minimal 0x00000001048f27e4 _ZN64_$LT$minimal..Stage$u20$as$u20$miniquad..event..EventHandler$GT$4draw28_$u7b$$u7b$closure$u7d$$u7d$17he8824ed8cc84aa3dE + 76
25 minimal 0x00000001048f35f8 _ZN13egui_miniquad6EguiMq3run28_$u7b$$u7b$closure$u7d$$u7d$17hc9881e831cb19482E + 48
26 minimal 0x00000001048f2588 _ZN4egui7context7Context3run17hb8b8f70d78e24ad6E + 132
27 minimal 0x00000001048f3110 _ZN13egui_miniquad6EguiMq3run17h74fb44a2c0388fbdE + 312
28 minimal 0x00000001048eec74 _ZN64_$LT$minimal..Stage$u20$as$u20$miniquad..event..EventHandler$GT$4draw17h0e838e72c20b41e7E + 184
29 minimal 0x0000000104d118ac _ZN8miniquad6native5macos23define_cocoa_view_class9draw_rect17hc72493deebeeaebbE + 204
30 AppKit 0x000000019f48bf74 -[_NSOpenGLViewBackingLayer display] + 716
31 QuartzCore 0x00000001a32ac29c _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 788
32 QuartzCore 0x00000001a3410904 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 456
33 QuartzCore 0x00000001a328e818 _ZN2CA11Transaction6commitEv + 652
34 AppKit 0x000000019efa6ae4 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 272
35 AppKit 0x000000019f684a28 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64
36 CoreFoundation 0x000000019bbf8db8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
37 CoreFoundation 0x000000019bbf8ca4 __CFRunLoopDoObservers + 532
38 CoreFoundation 0x000000019bbf82dc __CFRunLoopRun + 784
39 CoreFoundation 0x000000019bbf7878 CFRunLoopRunSpecific + 612
40 HIToolbox 0x00000001a52d7fa0 RunCurrentEventLoopInMode + 292
41 HIToolbox 0x00000001a52d7de4 ReceiveNextEventCommon + 672
42 HIToolbox 0x00000001a52d7b2c _BlockUntilNextEventMatchingListInModeWithFilter + 72
43 AppKit 0x000000019ee7d84c _DPSNextEvent + 632
44 AppKit 0x000000019ee7c9dc -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
45 AppKit 0x000000019ee70e0c -[NSApplication run] + 464
46 minimal 0x0000000104d0ad68 _ZN60_$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17he5cf6282fd2b36edE + 76
47 minimal 0x0000000104d168ac _ZN4objc7message8platform15send_unverified17h8a1246f244240d0bE + 132
48 minimal 0x00000001048f2238 _ZN8miniquad6native5macos3run17hf21035ff1ab8fee8E + 12740
49 minimal 0x00000001048f2fb4 _ZN8miniquad5start17hb0a6f82cc1bc737aE + 52
50 minimal 0x00000001048eefe8 _ZN7minimal4main17h4c9898d7beb123c8E + 416
51 minimal 0x00000001048edacc _ZN4core3ops8function6FnOnce9call_once17h9ff4ca3d6ee65369E + 20
52 minimal 0x00000001048ee770 _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hec3151742bd3c651E + 24
53 minimal 0x00000001048f2be0 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h3d4a9403f10b2f86E + 28
54 minimal 0x0000000104d358ec _ZN3std2rt19lang_start_internal17h9f0566e553deb11eE + 648
55 minimal 0x00000001048f2bac _ZN3std2rt10lang_start17h0e2ad8fbebaddedaE + 84
56 minimal 0x00000001048ef06c main + 36
57 dyld 0x000000019b7efe50 start + 2544
)
[examples/minimal.rs:43] &res = None
I've tested rfd
on miniquad by itself and on egui
by itself and it works on both (even in MacOS), so the problem seems to be specific to egui-miniquad
+ rfd
+ MacOS. I've read on some of the other issue threads and noticed that there might be issues related to which thread the window is created, so I also printed the current thread both on the first line of main
and before opening the window (but this example seems to be single threaded), and in both cases we get ThreadId(1)
.
The code I used is this (a smaller version of demo.rs
on egui-miniquad
):
use {egui_miniquad as egui_mq, miniquad as mq};
struct Stage {
egui_mq: egui_mq::EguiMq,
show_egui_demo_windows: bool,
egui_demo_windows: egui_demo_lib::DemoWindows,
color_test: egui_demo_lib::ColorTest,
pixels_per_point: f32,
}
impl Stage {
fn new(ctx: &mut mq::Context) -> Self {
Self {
egui_mq: egui_mq::EguiMq::new(ctx),
show_egui_demo_windows: true,
egui_demo_windows: Default::default(),
color_test: Default::default(),
pixels_per_point: ctx.dpi_scale(),
}
}
}
impl mq::EventHandler for Stage {
fn update(&mut self, _ctx: &mut mq::Context) {}
fn draw(&mut self, mq_ctx: &mut mq::Context) {
mq_ctx.clear(Some((1., 1., 1., 1.)), None, None);
mq_ctx.begin_default_pass(mq::PassAction::clear_color(0.0, 0.0, 0.0, 1.0));
mq_ctx.end_render_pass();
let dpi_scale = mq_ctx.dpi_scale();
// Run the UI code:
self.egui_mq.run(mq_ctx, |_mq_ctx, egui_ctx| {
egui::Window::new("egui ❤ miniquad").show(egui_ctx, |ui| {
// ###################
// RFD PART
if ui.button("RFD").clicked() {
println!("{:?}", std::thread::current().id());
let dialog = rfd::FileDialog::new();
println!("dialog created");
let res = rfd::FileDialog::new();
dbg!(&res);
if let Some(f) = res {
println!("chose: {f:?}");
}
}
});
});
// Draw things behind egui here
self.egui_mq.draw(mq_ctx);
// Draw things in front of egui here
mq_ctx.commit_frame();
}
fn mouse_motion_event(&mut self, _: &mut mq::Context, x: f32, y: f32) {
self.egui_mq.mouse_motion_event(x, y);
}
fn mouse_wheel_event(&mut self, _: &mut mq::Context, dx: f32, dy: f32) {
self.egui_mq.mouse_wheel_event(dx, dy);
}
fn mouse_button_down_event(
&mut self,
ctx: &mut mq::Context,
mb: mq::MouseButton,
x: f32,
y: f32,
) {
self.egui_mq.mouse_button_down_event(ctx, mb, x, y);
}
fn mouse_button_up_event(
&mut self,
ctx: &mut mq::Context,
mb: mq::MouseButton,
x: f32,
y: f32,
) {
self.egui_mq.mouse_button_up_event(ctx, mb, x, y);
}
fn char_event(
&mut self,
_ctx: &mut mq::Context,
character: char,
_keymods: mq::KeyMods,
_repeat: bool,
) {
self.egui_mq.char_event(character);
}
fn key_down_event(
&mut self,
ctx: &mut mq::Context,
keycode: mq::KeyCode,
keymods: mq::KeyMods,
_repeat: bool,
) {
self.egui_mq.key_down_event(ctx, keycode, keymods);
}
fn key_up_event(&mut self, _ctx: &mut mq::Context, keycode: mq::KeyCode, keymods: mq::KeyMods) {
self.egui_mq.key_up_event(keycode, keymods);
}
}
fn main() {
println!("{:?}", std::thread::current().id());
#[cfg(not(target_arch = "wasm32"))]
{
// Log to stdout (if you run with `RUST_LOG=debug`).
tracing_subscriber::fmt::init();
}
let conf = mq::conf::Conf {
high_dpi: true,
window_width: 1200,
window_height: 1024,
..Default::default()
};
mq::start(conf, |mut ctx| Box::new(Stage::new(&mut ctx)));
}
Same behaviour also happens with pick_folder
.
Tested on MacOS Ventura 13.2.1.
Thanks for reading. Any feedback is appreciated.