Files
o3de/Code/Tools/PythonBindingsExample/source/Application.h
T
jackalbe 580bd11715 {LYN-4372} fix for Python exit crash (#1600)
There is a crash when sys.exit() was being called since embedded Python
should not have control of the application lifetime. The Py_InspectFlag
puts the Python VM into 'inspection mode' which prevents the app
shutdown when any sys.exit() is invoked.

Notes:
* skips 'regset' extra command line in PythonBindingsExample
* added methods for handling PythonBindingsExample errors

Test: added Application_SystemExit_Blocked and
fixed up Application_Run_Fails now is Application_Run_Works
2021-06-28 10:28:49 -05:00

68 lines
2.2 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/Debug/TraceMessageBus.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
namespace PythonBindingsExample
{
struct ApplicationParameters;
class Application
: public AzToolsFramework::ToolsApplication
, protected AZ::Debug::TraceMessageBus::Handler
, protected AzToolsFramework::EditorPythonConsoleNotificationBus::Handler
{
public:
Application(int* argc, char*** argv);
~Application();
void SetUp();
bool Run();
void TearDown();
bool RunWithParameters(const ApplicationParameters& params);
inline void GetErrorCount(int& exceptionCount, int& errorCount)
{
exceptionCount = m_pythonExceptionCount;
errorCount = m_pythonErrorCount;
}
inline void ResetErrorCount()
{
m_pythonExceptionCount = 0;
m_pythonErrorCount = 0;
}
protected:
////////////////////////////////////////////////////////////////////////////////////////////
// TraceMessageBus
bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override;
bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override;
bool OnPrintf(const char* window, const char* message) override;
////////////////////////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorPythonConsoleNotifications
void OnTraceMessage(AZStd::string_view message) override;
void OnErrorMessage(AZStd::string_view message) override;
void OnExceptionMessage(AZStd::string_view message) override;
bool RunFileWithArgs(const ApplicationParameters& params);
void StartPythonVM();
void StopPythonVM();
protected:
bool m_showVerboseOutput = false;
bool m_startedPython = false;
int m_pythonExceptionCount = 0;
int m_pythonErrorCount = 0;
};
}