From 2eefc08d2e7aab40105b4d863613728d2795ac21 Mon Sep 17 00:00:00 2001 From: scottr Date: Wed, 9 Jun 2021 15:21:30 -0700 Subject: [PATCH 1/2] [cpack/stabilization/2106] fixed startup crash in project manager from installer build --- Code/Tools/ProjectManager/Source/PythonBindings.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index 3f0af7fa49..824cab4758 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -246,7 +246,7 @@ namespace O3DE::ProjectManager AZStd::string pyBasePath = Platform::GetPythonHomePath(PY_PACKAGE, m_enginePath.c_str()); if (!AZ::IO::SystemFile::Exists(pyBasePath.c_str())) { - AZ_Warning("python", false, "Python home path must exist. path:%s", pyBasePath.c_str()); + AZ_Assert(false, "Python home path must exist. path:%s", pyBasePath.c_str()); return false; } @@ -277,11 +277,9 @@ namespace O3DE::ProjectManager AZStd::lock_guard lock(m_lock); pybind11::gil_scoped_acquire acquire; - // Setup sys.path + // sanity import check int result = PyRun_SimpleString("import sys"); - AZ_Warning("ProjectManagerWindow", result != -1, "Import sys failed"); - result = PyRun_SimpleString(AZStd::string::format("sys.path.append('%s')", m_enginePath.c_str()).c_str()); - AZ_Warning("ProjectManagerWindow", result != -1, "Append to sys path failed"); + AZ_Error("ProjectManagerWindow", result != -1, "Import sys failed"); // import required modules m_cmake = pybind11::module::import("o3de.cmake"); @@ -299,7 +297,7 @@ namespace O3DE::ProjectManager } catch ([[maybe_unused]] const std::exception& e) { - AZ_Warning("ProjectManagerWindow", false, "Py_Initialize() failed with %s", e.what()); + AZ_Assert(false, "Py_Initialize() failed with %s", e.what()); return false; } } From 5061241992f69f1d2b0677de84941f13b6f80e44 Mon Sep 17 00:00:00 2001 From: scottr Date: Wed, 9 Jun 2021 17:03:13 -0700 Subject: [PATCH 2/2] [cpack/stabilization/2106] early out if sys import fails in PythonBindings::StartPython --- Code/Tools/ProjectManager/Source/PythonBindings.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index 824cab4758..bb6c05a472 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -278,8 +278,11 @@ namespace O3DE::ProjectManager pybind11::gil_scoped_acquire acquire; // sanity import check - int result = PyRun_SimpleString("import sys"); - AZ_Error("ProjectManagerWindow", result != -1, "Import sys failed"); + if (PyRun_SimpleString("import sys") != 0) + { + AZ_Assert(false, "Import sys failed"); + return false; + } // import required modules m_cmake = pybind11::module::import("o3de.cmake"); @@ -293,7 +296,7 @@ namespace O3DE::ProjectManager // make sure the engine is registered RegisterThisEngine(); - return result == 0 && !PyErr_Occurred(); + return !PyErr_Occurred(); } catch ([[maybe_unused]] const std::exception& e) {