diff --git a/Engine/source/app/mainLoop.cpp b/Engine/source/app/mainLoop.cpp index f89b4c435..2819d153d 100644 --- a/Engine/source/app/mainLoop.cpp +++ b/Engine/source/app/mainLoop.cpp @@ -623,6 +623,11 @@ bool StandardMainLoop::doMainLoop() return keepRunning; } +S32 StandardMainLoop::getReturnStatus() +{ + return Process::getReturnStatus(); +} + void StandardMainLoop::setRestart(bool restart ) { gRequiresRestart = restart; diff --git a/Engine/source/app/mainLoop.h b/Engine/source/app/mainLoop.h index 4c2b186bd..b7baad503 100644 --- a/Engine/source/app/mainLoop.h +++ b/Engine/source/app/mainLoop.h @@ -41,6 +41,9 @@ public: /// Shut down the core libraries and call registered shutdown fucntions. static void shutdown(); + /// Gets the return status code of the current process. + static S32 getReturnStatus(); + static void setRestart( bool restart ); static bool requiresRestart(); diff --git a/Engine/source/cinterface/cinterface.cpp b/Engine/source/cinterface/cinterface.cpp index 2d9a729d3..f87ffaea7 100644 --- a/Engine/source/cinterface/cinterface.cpp +++ b/Engine/source/cinterface/cinterface.cpp @@ -132,6 +132,11 @@ extern "C" { } + S32 torque_getreturnstatus() + { + return StandardMainLoop::getReturnStatus(); + } + // signal an engine shutdown (as with the quit(); console command) void torque_enginesignalshutdown() { diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index 2dea93f44..52ff68a00 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -1517,11 +1517,12 @@ ConsoleFunction( realQuit, void, 1, 1, "" ) //----------------------------------------------------------------------------- -DefineConsoleFunction( quitWithErrorMessage, void, ( const char* message ),, +DefineConsoleFunction( quitWithErrorMessage, void, ( const char* message, S32 status ), (0), "Display an error message box showing the given @a message and then shut down the engine and exit its process.\n" "This function cleanly uninitialized the engine and then exits back to the system with a process " "exit status indicating an error.\n\n" - "@param message The message to log to the console and show in an error message box.\n\n" + "@param message The message to log to the console and show in an error message box.\n" + "@param status The status code to return to the OS.\n\n" "@see quit\n\n" "@ingroup Platform" ) { @@ -1532,7 +1533,20 @@ DefineConsoleFunction( quitWithErrorMessage, void, ( const char* message ),, // as the script code should not be allowed to pretty much hard-crash the engine // and prevent proper shutdown. Changed this to use postQuitMessage. - Platform::postQuitMessage( -1 ); + Platform::postQuitMessage( status ); +} + +//----------------------------------------------------------------------------- + +DefineConsoleFunction( quitWithStatus, void, ( S32 status ), (0), + "Shut down the engine and exit its process.\n" + "This function cleanly uninitializes the engine and then exits back to the system with a given " + "return status code.\n\n" + "@param status The status code to return to the OS.\n\n" + "@see quitWithErrorMessage\n\n" + "@ingroup Platform" ) +{ + Platform::postQuitMessage(status); } //----------------------------------------------------------------------------- diff --git a/Engine/source/core/util/journal/process.cpp b/Engine/source/core/util/journal/process.cpp index a2520337d..3911cd0a1 100644 --- a/Engine/source/core/util/journal/process.cpp +++ b/Engine/source/core/util/journal/process.cpp @@ -43,15 +43,21 @@ static Process* _theOneProcess = NULL; ///< the one instance of the Process clas //----------------------------------------------------------------------------- -void Process::requestShutdown() +void Process::requestShutdown(S32 status) { Process::get()._RequestShutdown = true; + Process::get()._ReturnStatus = status; +} + +S32 Process::getReturnStatus() +{ + return Process::get()._ReturnStatus; } //----------------------------------------------------------------------------- Process::Process() -: _RequestShutdown( false ) +: _RequestShutdown( false ), _ReturnStatus( 0 ) { } diff --git a/Engine/source/core/util/journal/process.h b/Engine/source/core/util/journal/process.h index 4d21898d9..d5633558c 100644 --- a/Engine/source/core/util/journal/process.h +++ b/Engine/source/core/util/journal/process.h @@ -64,7 +64,7 @@ public: static bool processEvents(); /// Ask the processEvents() function to shutdown. - static void requestShutdown(); + static void requestShutdown(S32 status = 0); static void notifyInit(Delegate del, F32 order = PROCESS_DEFAULT_ORDER) @@ -149,6 +149,9 @@ public: /// Trigger the registered shutdown functions static bool shutdown(); + /// get the current return status code we've been asked to end with. + static S32 getReturnStatus(); + private: friend class StandardMainLoop; @@ -167,6 +170,7 @@ private: Signal _signalShutdown; bool _RequestShutdown; + S32 _ReturnStatus; }; /// Register a command line handling function. diff --git a/Engine/source/main/main.cpp b/Engine/source/main/main.cpp index 1638b5b33..9728f37ec 100644 --- a/Engine/source/main/main.cpp +++ b/Engine/source/main/main.cpp @@ -321,7 +321,7 @@ S32 TorqueMain(S32 argc, const char **argv) Platform::restartInstance(); // Return. - return 0; + return StandardMainLoop::getReturnStatus(); } #endif //TORQUE_SHARED diff --git a/Engine/source/platform/platform.h b/Engine/source/platform/platform.h index d390eef5c..81f6165c1 100644 --- a/Engine/source/platform/platform.h +++ b/Engine/source/platform/platform.h @@ -204,7 +204,7 @@ namespace Platform bool excludeOtherInstances(const char *string); bool checkOtherInstances(const char *string); void restartInstance(); - void postQuitMessage(const U32 in_quitVal); + void postQuitMessage(const S32 in_quitVal); void forceShutdown(S32 returnValue); // Debug diff --git a/Engine/source/platformWin32/winProcessControl.cpp b/Engine/source/platformWin32/winProcessControl.cpp index f20905428..69cab8ad8 100644 --- a/Engine/source/platformWin32/winProcessControl.cpp +++ b/Engine/source/platformWin32/winProcessControl.cpp @@ -23,7 +23,7 @@ #include "platformWin32/platformWin32.h" #include "core/strings/stringFunctions.h" -void Platform::postQuitMessage(const U32 in_quitVal) +void Platform::postQuitMessage(const S32 in_quitVal) { if (!Platform::getWebDeployment()) PostQuitMessage(in_quitVal); diff --git a/Engine/source/platformWin32/winWindow.cpp b/Engine/source/platformWin32/winWindow.cpp index 5c2bac019..75df7d431 100644 --- a/Engine/source/platformWin32/winWindow.cpp +++ b/Engine/source/platformWin32/winWindow.cpp @@ -375,6 +375,7 @@ extern "C" { bool torque_engineinit(S32 argc, const char **argv); S32 torque_enginetick(); + S32 torque_getreturnstatus(); bool torque_engineshutdown(); }; @@ -390,7 +391,7 @@ S32 TorqueMain(int argc, const char **argv) torque_engineshutdown(); - return 0; + return torque_getreturnstatus(); } diff --git a/Engine/source/platformX86UNIX/x86UNIXMain.cpp b/Engine/source/platformX86UNIX/x86UNIXMain.cpp index 4ffb262c9..e0f252e0d 100644 --- a/Engine/source/platformX86UNIX/x86UNIXMain.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXMain.cpp @@ -121,6 +121,7 @@ extern "C" { bool torque_engineinit(int argc, const char **argv); int torque_enginetick(); + S32 torque_getreturnstatus(); bool torque_engineshutdown(); int torque_unixmain(int argc, const char **argv) @@ -135,7 +136,7 @@ extern "C" torque_engineshutdown(); - return 0; + return torque_getreturnstatus(); } } diff --git a/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp b/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp index 1930af2b5..ed0b2aac6 100644 --- a/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXProcessControl.cpp @@ -37,9 +37,6 @@ //----------------------------------------------------------------------------- // This is a mainly a debugging function for intercepting a nonzero exit code // and generating a core dump for a stack trace. -// Need an S64 here because postQuitMessage uses a U32, and -// forceshutdown uses an S32. So S64 is needed to -// accomodate them both static void CheckExitCode(S64 exitCode) { if (exitCode != 0) @@ -141,7 +138,7 @@ void ProcessControlInit() } //----------------------------------------------------------------------------- -void Platform::postQuitMessage(const U32 in_quitVal) +void Platform::postQuitMessage(const S32 in_quitVal) { // if we have a window send a quit event, otherwise just force shutdown #if 0 @@ -171,8 +168,6 @@ void Platform::debugBreak() //----------------------------------------------------------------------------- void Platform::forceShutdown(S32 returnValue) { - CheckExitCode(returnValue); - #if 0 // if a dedicated server is running, turn it off if (x86UNIXState->isDedicated() && Game->isRunning()) diff --git a/Engine/source/windowManager/win32/winDispatch.cpp b/Engine/source/windowManager/win32/winDispatch.cpp index 7038d0a29..15ebd4048 100644 --- a/Engine/source/windowManager/win32/winDispatch.cpp +++ b/Engine/source/windowManager/win32/winDispatch.cpp @@ -450,7 +450,7 @@ static bool _dispatch(HWND hWnd,UINT message,WPARAM wParam,WPARAM lParam) // Quit indicates that we're not going to receive anymore Win32 messages. // Therefore, it's appropriate to flag our event loop for exit as well, // since we won't be getting any more messages. - Process::requestShutdown(); + Process::requestShutdown((S32)wParam); break; }