1
0
mirror of synced 2024-11-28 09:30:51 +01:00

fix: Crash when closing the file picker without picking a file

This commit is contained in:
WerWolv 2022-07-07 23:28:40 +02:00
parent e34f94bb79
commit 461c5eac3e

View File

@ -71,7 +71,7 @@ namespace hex::fs {
bool openFileBrowser(DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback, const std::string &defaultPath) {
NFD::Init();
nfdchar_t *outPath;
nfdchar_t *outPath = nullptr;
nfdresult_t result;
switch (mode) {
case DialogMode::Open:
@ -87,6 +87,7 @@ namespace hex::fs {
hex::unreachable();
}
if (result == NFD_OKAY && outPath != nullptr) {
std::fs::path path;
#if defined(OS_LINUX)
// xdg-desktop-portal, which is the file picker backend used on Linux, returns all paths with URI encoding.
@ -97,7 +98,6 @@ namespace hex::fs {
path = reinterpret_cast<char8_t*>(outPath);
#endif
if (result == NFD_OKAY) {
callback(path);
NFD::FreePath(outPath);
}