Save File Dialog in UE4 results in crashes

Hi all,

So I’ve recently been trying to implement a windows SaveFileDialog to a UE4 project. Using khalibloo’s implementation in this post, I managed to get it fully working. Now although it works as it should, it sometimes randomly crashes at a break point in MallocTBB.cpp (67):

67: NewPtr = scalable_malloc( Size );

Exception thrown: read access violation.
    temp was 0x6900760061.

Here is my callstack , which seems to only involve some engine functions. My output log also gets cluttered with some windows related messages (“Le lecteur spécifié est introuvable” = Drive can’t be found).

I’ve managed to pinpoint it down to the way I’m setting the ofn->FileName variable in the FileDialog class (cpp, header). This is how I’m creating the dialog from a BP Library, here. If I comment out the FileName line everything works fine with no crashes (still the cluttered output log tho).

Does anyone have an idea on how to fix that? I spent the past few days trying to play around with it but I can’t get my head around it.

a crash inside scalable_malloc is memory corruption, and the usual suspect with these comdlg recipes is the modal dialog pumping windows messages on the game thread while the rest of the engine keeps allocating, plus a parent handle that goes stale between frames. its very hard to pin down inside someone elses snippet.

the safer shape is a dialog that never blocks: call it from a runtime module, let the os window do its thing, and get the path back through an event on the game thread. Async Runtime File Dialog, a native file picker plugin for Unreal Engine 5, has that as a Save File Picker node with On Saved / On Cancelled, packaged builds, 5.0-5.8: Async Runtime File Dialog — Native OS File Picker for Blueprints | Fab