Application crashes when file_dialog path encounters characters like æ ø å
Version of Dear PyGui
Version: 1.8.0 Operating System: Windows 10
My Issue/Question
Application crashes if you have a character like æ, ø, å in your path when you press OK or CANCEL.
To Reproduce
Steps to reproduce the behavior:
- open a file_dialog
- Navigate to a path with a character like ø, æ or å
- Click on either ok or cancel
- Application crashes
Expected behavior
Executes either callback or cancel_callback.
Standalone, minimal, complete and verifiable example
import dearpygui.dearpygui as dpg
import os
new_folder_name = "new_folder_with_øæå"
current_dir = os.getcwd()
new_folder_path = os.path.join(current_dir, new_folder_name)
if (os.path.exists(new_folder_path) == False):
os.makedirs(new_folder_path)
dpg.create_context()
def callback(sender, app_data):
print('OK was clicked.')
def cancel_callback(sender, app_data):
print('Cancel was clicked.')
print("Sender: ", sender)
print("App Data: ", app_data)
width, height = 600,600
dpg.add_file_dialog(
directory_selector=True, show=False, callback=callback, tag="dialog",
cancel_callback=cancel_callback, width=400 ,height=400 )
dpg.show_item("dialog")
dpg.create_viewport(title='File Name', width=width, height=height)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
It crashes in mvFileDialog::getInfoDict(), in the very first call to PyDict_SetItemString(), which extracts file name from ImGuiFileDialog and feeds it into ToPyString() (and consequently PyUnicode_FromString()):
PyDict_SetItemString(dict, "file_path_name", mvPyObject(ToPyString(_instance.GetFilePathName())));
The problem is, GetFilePathName() returns an ANSI-encoded (single-byte) string, whereas PyUnicode_FromString() expects a UTF-8 strings and treats it as such. I believe it goes over the trailing zero or something like that. Or maybe it stumps upon an assertion of some kind and crashes.
I'm not sure whether ANSI-encoded strings are Windows-specific behavior or they show up on all platforms (I'd bet on Windows-specific). The bad news are, the file dialog doesn't even display such names correctly. That is, strings inside of file dialog must be UTF-8 rather than ANSI; it's a bug in ImGuiFileDialog and not in DPG. Not sure if we can fix it in ImGuiFileDialog though because ~it's a submodule repo~ - scratch that, even though it's a third-party library, it's committed directly into DPG. Technically we can fix it or even update ImGuiFileDialog from its source repo (if it works on old ImGui, that is).
Another piece of wisdom can be found in this comment on #299.