Crash on exit in PIE

I’m working on adding a main menu with a quit button. The OnClicked event simply does FGenericPlatformMisc::RequestExit(false);.

I then get an exception from the engine. Specifically, EditorEngine.cpp, line 854.

void UEditorEngine::FinishDestroy()
{
	if ( !HasAnyFlags(RF_ClassDefaultObject) )
	{
		// this needs to be already cleaned up
		check(PlayWorld == NULL);

The final line is what’s triggering the exception. According to the watch, PlayWorld and this are both None, but have valid memory addresses:

+		this	0x000000001fe1ab00 (Name=0x00000000027d60d0 "None")	UEditorEngine *
+		PlayWorld	0x000000004e7f3580 (Name=0x00000000027d60d0 "None")	UWorld *

I believe this means they’ve been marked for deletion, but haven’t actually been deleted. Stacktrace is:

>	UE4Editor-UnrealEd.dll!UEditorEngine::FinishDestroy() Line 854	C++
 	UE4Editor-CoreUObject.dll!UObject::ConditionalFinishDestroy() Line 685	C++
 	UE4Editor-CoreUObject.dll!IncrementalPurgeGarbage(bool bUseTimeLimit, float TimeLimit) Line 1019	C++
 	UE4Editor-CoreUObject.dll!StaticExit() Line 3718	C++
 	UE4Editor-CoreUObject.dll!TBaseStaticDelegateInstance<void __cdecl(void)>::ExecuteIfSafe() Line 921	C++
 	UE4Editor.exe!TBaseMulticastDelegate<void>::Broadcast() Line 809	C++
 	UE4Editor.exe!FEngineLoop::AppPreExit() Line 2942	C++
 	UE4Editor.exe!FEngineLoop::Exit() Line 2203	C++
 	UE4Editor.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 153	C++
 	UE4Editor.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 189	C++
 	[External Code]	

I have no idea if this is an issue specific to 4.9 or something wrong in my project, as I’ve only just now added the RequestExit(false) call. Pressing esc to get out of PIE works fine, with no issues. Is it possible that some oddity in my project is preventing the timely deletion of PlayWorld?

Hey -

Are you setting up the quit button though code or UMG? If it is being done in code can you post the code where you set it up? If you’re using UMG can you post a screenshot of the setup in the editor?

Cheers

Through code.

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SMainMenuUI::Construct(const FArguments& InArgs)
{
	MainMenuHUD = InArgs._MainMenuHUD;

	ChildSlot
		[
			SNew(SOverlay)
			+ SOverlay::Slot()
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Top)
			[
				SNew(STextBlock)
				.ColorAndOpacity(FLinearColor::White)
				.ShadowColorAndOpacity(FLinearColor::Black)
				.ShadowOffset(FIntPoint(-1, 1))
				.Font(FSlateFontInfo("Arial", 26))
				.Text(FText::FromString("Main Menu"))
			]
			+ SOverlay::Slot()
				.HAlign(HAlign_Center)
				.VAlign(VAlign_Center)
				[
					SNew(SVerticalBox)
					+ SVerticalBox::Slot()
					[
						SNew(SButton)
						.Text(FText::FromString("Play Game!"))
						.OnClicked(this, &SMainMenuUI::PlayGameClicked)
					]
					+ SVerticalBox::Slot()
						[
							SNew(SButton)
							.Text(FText::FromString("Quit Game"))
							.OnClicked(this, &SMainMenuUI::QuitGameClicked)
						]
				]
		];
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION

FReply SMainMenuUI::QuitGameClicked()
{    
	FGenericPlatformMisc::RequestExit(false);

	return FReply::Handled();
}

Hey -

It looks like the code you’re using will close the entire application. When running through PIE this is trying to close the editor as well which is what is causing the problems. It would be best to issue the console command “quit” or “exit” to handle exiting out of PIE.

Cheers

That fixed it. Thanks for the help.