rfd icon indicating copy to clipboard operation
rfd copied to clipboard

Bad interaction between this crate and `mlua`

Open setzer22 opened this issue 3 years ago • 3 comments

More details here: https://github.com/khvzak/mlua/issues/184

I'm trying to figure out a very strange interaction between rfd and mlua that breaks the latter in very subtle ways. This issue can only be reproduced when using the gtk-3 backend on Linux. I tried switching to xdg-portal and that one seems unaffected.

I'm reporting this here in case you have an idea of something in the gtk-3 backend that might be introducing some subtle UB? I honestly don't know where the issue lies in, so I'm reporting in both places :smile:

setzer22 avatar Jul 08 '22 17:07 setzer22

in case you have an idea of something in the gtk-3 backend that might be introducing some subtle UB

The better question would be, do you know something that can not cause UB in the gtk3 backend. That's why we are trying to fade it out in favor of xdg-portal, as portal backend is soooo much cleaner and done fully in safe Rust (the whole stack is rust based, no C libraries needed).

This ironic response aside, non async variant of gtk3 done without multi threading should be relatively UB free, so I would like to investigate this more, but I suspect that this will be a nightmare to debug, we essentially have two C libraries interacting with each other somehow. The only idea I have so far is the fact that gtk3 starts it's own event loop, and it can affect mlua somehow? Just a guess so don't quote me on that.

PolyMeilex avatar Jul 08 '22 18:07 PolyMeilex

The better question would be, do you know something that can not cause UB in the gtk3 backend.

Hehe, never been a GTK-3 fan. I'm honestly not surprised :sweat_smile: I actually only discovered the xdg-portal feature while looking into this bug, so if you tell me it's the preferred backend then I won't think twice about it. It's also much nicer in that you get your native file picker (so, a Qt file picker on KDE).

so I would like to investigate this more

Please let me know if I can help! The issue is oddly specific, since I only managed to reproduce it when enabling the luau feature of mlua plus the gtk-3 backend of rfd. I haven't been able to reproduce this on every other combination :grimacing:, but such is the nature of UB sometimes :shrug:

setzer22 avatar Jul 08 '22 18:07 setzer22

Hehe, never been a GTK-3 fan. I'm honestly not surprised

I actually like it, and use it for my apps (GTK4 to be precise), but it is a full-blown UI framework, not a file dialog library, so it essentially wants to take over the control over your process, start its own event loop, and everything else that comes with a framework. So using it in a framework-agnostic and god forbid multithreaded (in async mode) dialog library is not a great experience. Never had any UB when writing apps with it on top of gtk-rs. XDG Portal in contrary is a protocol designed for being as agnostic as possible, and implemented in async first fashion, so it's a perfect fit for RFD.

PolyMeilex avatar Jul 08 '22 18:07 PolyMeilex