I created a c++ function with openfiledialog and savefiledialog to save my game. Loading and saving work well. But when I click the Cancel button, the software crash.
How can I resolve this issue?
I created a c++ function with openfiledialog and savefiledialog to save my game. Loading and saving work well. But when I click the Cancel button, the software crash.
How can I resolve this issue?
Can you provide the code you wrote so that we can see what causes the crash? Perhaps your code doesn’t have a cancel function which causes it to crash?
Here is the part of my code that open the dialog window and get the file path and the file name.
void* ParentWindowHandle = GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle();
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (DesktopPlatform)
{
//Opening the file picker!
uint32 SelectionFlag = 0; //A value of 0 represents single file selection while a value of 1 represents multiple file selection
if (DesktopPlatform->OpenFileDialog(ParentWindowHandle, DialogTitle, DefaultPath, FString(""), FileTypes, SelectionFlag, OutFilePath))
{
FileName = FPaths::GetBaseFilename(OutFilePath[0]);
}
else
{
return; // Exit the function here if the file dialog was cancelled
}
}
Hmm, I can’t see anything wrong with the code. Perhaps someone who have done this before can help out.
Can you try passing nullptr instead the ParentWindowHandle?
In one of my projects I’m using the ‘OpenDirectoryDialog’ function only, using nullptr as window handle param and it works fine.
In the Engine code, I only found Editor Modules passing Handles of windows generated via Slate (using FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr)).
And I found this in HoloLensImageResourcesCustomization.cpp:
void PickGltfFor(const FString& ModelPath)
{
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (!DesktopPlatform)
{
return;
}
FText Title = FText::FromString("glb");
FString TitleExtensions = TEXT("*.glb");
TArray<FString> OutFiles;
const FString Filter = FString::Printf(TEXT("%s files (%s)|%s"), *Title.ToString(), *TitleExtensions, *TitleExtensions);
const FString DefaultPath = FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_OPEN);
if (DesktopPlatform->OpenFileDialog(nullptr, FText::Format(LOCTEXT("GltfPickerDialogTitle", "Choose a {0} file"), Title).ToString(), DefaultPath, TEXT(""), Filter, EFileDialogFlags::None, OutFiles))
{
check(OutFiles.Num() == 1);
FString SourceImagePath = FPaths::ConvertRelativePathToFull(OutFiles[0]);
FEditorDirectories::Get().SetLastDirectory(ELastDirectory::GENERIC_OPEN, FPaths::GetPath(SourceImagePath));
if (ModelPath != SourceImagePath)
{
IFileManager::Get().Copy(*ModelPath, *SourceImagePath);
}
}
}
Using nullptr as handle resolve my issue.
Thank you