Files
UnrealEngineUWP/Engine/Source/Programs/CrashReportClient/Private/Mac/CrashReportClientMainMac.cpp
brandon schaefer a715ea4f14 Deprecate GIsRequestingExit
Get GIsRequestingExit now by IsEngineRequestingExit()

Set GIsRequestingExit now by RequestEngineExit(const TCHAR* Reason) or RequestEngineExit(const FString& Reason)
NOTE If Reason is 4 or less chars it will generate an ensure to force a reason to exit

The reason behind this change is right now setting GIsRequestingExit to true can cause many things to break mainly early on and with out any sort of log warning we have entered this state. We should wrap this behind a function to allow for proper handling

#rb Chris.Babcock, Michael.Trepka, Michael.Noland
#jira UE-79933
[FYI] Michael.Noland


#ROBOMERGE-SOURCE: CL 8649683 via CL 8653683
#ROBOMERGE-BOT: (v417-8656536)

[CL 8658680 by brandon schaefer in Main branch]
2019-09-12 14:21:26 -04:00

117 lines
3.0 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "CrashReportClientApp.h"
#include "HAL/ExceptionHandling.h"
#include "Mac/MacPlatformCrashContext.h"
#include "Mac/MacPlatformProcess.h"
#include "Mac/CocoaThread.h"
#include "HAL/PlatformApplicationMisc.h"
/**
* Because crash reporters can crash, too - only used for Sandboxed applications
*/
void CrashReporterCrashHandler(const FGenericCrashContext& GenericContext)
{
// We never emit a crash report in Sandboxed builds from CRC as if we do, then the crashed application's
// crash report is overwritten by the CRC's when trampolining into the Apple Crash Reporter.
_Exit(0);
}
static FString GSavedCommandLine;
static bool GIsUnattended;
@interface UE4AppDelegate : NSObject <NSApplicationDelegate, NSFileManagerDelegate>
{
}
@end
@implementation UE4AppDelegate
//handler for the quit apple event used by the Dock menu
- (void)handleQuitEvent:(NSAppleEventDescriptor*)Event withReplyEvent:(NSAppleEventDescriptor*)ReplyEvent
{
[self requestQuit:self];
}
- (IBAction)requestQuit:(id)Sender
{
RequestEngineExit(TEXT("Mac CrashReportClient RequestQuit"));
}
- (void) runGameThread:(id)Arg
{
FPlatformMisc::SetGracefulTerminationHandler();
// For sandboxed applications CRC can never report a crash, or we break trampolining into Apple's crash reporter.
if(FPlatformProcess::IsSandboxedApplication())
{
FPlatformMisc::SetCrashHandler(CrashReporterCrashHandler);
}
RunCrashReportClient(*GSavedCommandLine);
[NSApp terminate: self];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)Sender;
{
if(!IsEngineExitRequested() || ([NSThread gameThread] && [NSThread gameThread] != [NSThread mainThread]))
{
[self requestQuit:self];
return NSTerminateLater;
}
else
{
return NSTerminateNow;
}
}
- (void)applicationDidFinishLaunching:(NSNotification *)Notification
{
//install the custom quit event handler
NSAppleEventManager* appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
if (!GIsUnattended)
{
FPlatformApplicationMisc::ActivateApplication();
}
RunGameThread(self, @selector(runGameThread:));
}
@end
int main(int argc, char *argv[])
{
for (int32 Option = 1; Option < argc; Option++)
{
GSavedCommandLine += TEXT(" ");
FString Argument(ANSI_TO_TCHAR(argv[Option]));
if (Argument.Contains(TEXT(" ")))
{
if (Argument.Contains(TEXT("=")))
{
FString ArgName;
FString ArgValue;
Argument.Split( TEXT("="), &ArgName, &ArgValue );
Argument = FString::Printf( TEXT("%s=\"%s\""), *ArgName, *ArgValue );
}
else
{
Argument = FString::Printf(TEXT("\"%s\""), *Argument);
}
}
else if (Argument.ToLower() == TEXT("-unattended"))
{
GIsUnattended = true;
}
GSavedCommandLine += Argument;
}
SCOPED_AUTORELEASE_POOL;
[NSApplication sharedApplication];
[NSApp setDelegate:[UE4AppDelegate new]];
[NSApp run];
return 0;
}