diff --git a/Source/UnrealEnginePython/Private/PipConsoleManager.cpp b/Source/UnrealEnginePython/Private/PipConsoleManager.cpp index 7a55b212b..01939be8a 100644 --- a/Source/UnrealEnginePython/Private/PipConsoleManager.cpp +++ b/Source/UnrealEnginePython/Private/PipConsoleManager.cpp @@ -1,8 +1,9 @@ // Fill out your copyright notice in the Description page of Project Settings. +#include "PipConsoleManager.h" #include "UnrealEnginePythonPrivatePCH.h" #include "IPluginManager.h" -#include "PipConsoleManager.h" + UPipConsoleManager::UPipConsoleManager(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) diff --git a/Source/UnrealEnginePython/Private/PythonComponent.cpp b/Source/UnrealEnginePython/Private/PythonComponent.cpp index 85d98b7c0..9a5401cd7 100644 --- a/Source/UnrealEnginePython/Private/PythonComponent.cpp +++ b/Source/UnrealEnginePython/Private/PythonComponent.cpp @@ -153,7 +153,6 @@ void UPythonComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) Py_XDECREF(ep_ret); } - Py_DECREF(bp_ret); Super::EndPlay(EndPlayReason); } diff --git a/Source/UnrealEnginePython/Private/UEPyEngine.cpp b/Source/UnrealEnginePython/Private/UEPyEngine.cpp index 97699f2f0..4ee7ff66f 100644 --- a/Source/UnrealEnginePython/Private/UEPyEngine.cpp +++ b/Source/UnrealEnginePython/Private/UEPyEngine.cpp @@ -770,16 +770,10 @@ PyObject *py_unreal_engine_create_and_dispatch_when_ready(PyObject * self, PyObj FGraphEventRef task = FFunctionGraphTask::CreateAndDispatchWhenReady([&, py_callable_s, py_params_s]() { //UE_LOG(LogPython, Log, TEXT("In task graph, are in game thread? %d"), IsInGameThread()); - -<<<<<<< HEAD -======= - - FGraphEventRef task = FFunctionGraphTask::CreateAndDispatchWhenReady([&]() { ->>>>>>> pr/9 FScopePythonGIL gil; PyObject *ret = nullptr; PyObject *py_tuple_params = nullptr; - + //do we have parameters? if (py_params_s) { @@ -793,16 +787,14 @@ PyObject *py_unreal_engine_create_and_dispatch_when_ready(PyObject * self, PyObj } //did we get a valid return from our call? - if (ret) + if (ret) { Py_DECREF(ret); } - else + else { unreal_engine_py_log_error(); } -<<<<<<< HEAD - if (py_params_s) { Py_DECREF(py_params_s); @@ -813,21 +805,9 @@ PyObject *py_unreal_engine_create_and_dispatch_when_ready(PyObject * self, PyObj } Py_DECREF(py_callable_s); }, TStatId(), nullptr, ENamedThreads::GameThread); - + Py_INCREF(Py_None); return Py_None; -======= - Py_DECREF(py_callable); - }, TStatId(), nullptr, (ENamedThreads::Type)named_thread); - - - Py_BEGIN_ALLOW_THREADS; - FTaskGraphInterface::Get().WaitUntilTaskCompletes(task); - Py_END_ALLOW_THREADS; - // TODO Implement signal triggering in addition to WaitUntilTaskCompletes - // FTaskGraphInterface::Get().TriggerEventWhenTaskCompletes - - Py_RETURN_NONE; } @@ -862,7 +842,6 @@ PyObject *py_unreal_engine_main_thread_call(PyObject * self, PyObject * args) Py_END_ALLOW_THREADS; Py_RETURN_NONE; ->>>>>>> pr/9 } #endif diff --git a/Source/UnrealEnginePython/Private/UEPyLambda.cpp b/Source/UnrealEnginePython/Private/UEPyLambda.cpp index 731a87ba8..9b395172d 100644 --- a/Source/UnrealEnginePython/Private/UEPyLambda.cpp +++ b/Source/UnrealEnginePython/Private/UEPyLambda.cpp @@ -1,3 +1,4 @@ +#include "UEPyLambda.h" #include "UnrealEnginePythonPrivatePCH.h" PyObject * py_ue_run_on_game_thread(PyObject* PyFunction, PyObject* Args) diff --git a/Source/UnrealEnginePython/Private/UnrealEnginePython.cpp b/Source/UnrealEnginePython/Private/UnrealEnginePython.cpp index ff2f8a6cc..db81d190d 100644 --- a/Source/UnrealEnginePython/Private/UnrealEnginePython.cpp +++ b/Source/UnrealEnginePython/Private/UnrealEnginePython.cpp @@ -435,12 +435,6 @@ void FUnrealEnginePythonModule::StartupModule() } else { -<<<<<<< HEAD - // TODO gracefully manage the error - UE_LOG(LogPython, Warning, TEXT("ue_site not found (if you don't use the startup file ignore this warning)")); - //unreal_engine_py_log_error(); - } -======= #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 6 if (PyErr_ExceptionMatches(PyExc_ModuleNotFoundError)) { @@ -455,7 +449,6 @@ void FUnrealEnginePythonModule::StartupModule() unreal_engine_py_log_error(); #endif } ->>>>>>> pr/9 // release the GIL PyThreadState *UEPyGlobalState = PyEval_SaveThread(); @@ -635,7 +628,7 @@ PyObject *ue_py_register_module(const char *name) void FUnrealEnginePythonModule::AddPathToSysPath(const FString& Path) { - PythonGILAcquire(); + FScopePythonGIL gil; PyObject *py_sys = PyImport_ImportModule("sys"); PyObject *py_sys_dict = PyModule_GetDict(py_sys); @@ -644,8 +637,6 @@ void FUnrealEnginePythonModule::AddPathToSysPath(const FString& Path) char *charPath = TCHAR_TO_UTF8(*Path); PyObject *py_scripts_path = PyUnicode_FromString(charPath); PyList_Insert(py_path, 0, py_scripts_path); - - PythonGILRelease(); } void FUnrealEnginePythonModule::AddPythonDependentPlugin(const FString& PluginName) @@ -660,7 +651,7 @@ void FUnrealEnginePythonModule::AddPythonDependentPlugin(const FString& PluginNa FString PyModulePath = FString::Printf(TEXT("%s/upymodule.json"), *ScriptsPath); FString RunImport = FString::Printf(TEXT("import upymodule_importer\nupymodule_importer.parseJson('%s')"), *PyModulePath); - PythonGILAcquire(); + FScopePythonGIL gil; if (PyRun_SimpleString(TCHAR_TO_UTF8(*RunImport)) == 0) { UE_LOG(LogPython, Log, TEXT("%s Plugin upymodule.json parsed"), *PluginName); @@ -668,8 +659,6 @@ void FUnrealEnginePythonModule::AddPythonDependentPlugin(const FString& PluginNa else { unreal_engine_py_log_error(); } - - PythonGILRelease(); } #undef LOCTEXT_NAMESPACE diff --git a/Source/UnrealEnginePython/Public/PipConsoleManager.h b/Source/UnrealEnginePython/Public/PipConsoleManager.h index 51cbec9d7..d1c9f051c 100644 --- a/Source/UnrealEnginePython/Public/PipConsoleManager.h +++ b/Source/UnrealEnginePython/Public/PipConsoleManager.h @@ -2,6 +2,7 @@ #pragma once +#include "Runtime/Engine/Classes/GameFramework/CheatManager.h" #include "PipConsoleManager.generated.h" /** diff --git a/Source/UnrealEnginePython/UnrealEnginePython.Build.cs b/Source/UnrealEnginePython/UnrealEnginePython.Build.cs index 9d4e2625a..0c717084e 100644 --- a/Source/UnrealEnginePython/UnrealEnginePython.Build.cs +++ b/Source/UnrealEnginePython/UnrealEnginePython.Build.cs @@ -23,9 +23,9 @@ protected string ThirdPartyPythonHome // otherwise specify the path of your python installation - //private string pythonHome = "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/"; + //private string PythonHome = "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/"; // on Linux an include;libs syntax is expected: - //private string pythonHome = "/usr/local/include/python3.6;/usr/local/lib/libpython3.6.so" + //private string PythonHome = "/usr/local/include/python3.6;/usr/local/lib/libpython3.6.so" //Swap python versions here private string PythonType = "Python36"; @@ -229,62 +229,62 @@ public UnrealEnginePython(TargetInfo Target) }); } - if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32)) - { - if (UseThirdPartyPython) - { - PythonHome = ThirdPartyPythonHome; + if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32)) + { + if (UseThirdPartyPython) + { + PythonHome = ThirdPartyPythonHome; - System.Console.WriteLine("Using Embedded Python at: " + PythonHome); - PublicIncludePaths.Add(PythonHome); - string libPath = Path.Combine(PythonHome, "Lib", string.Format("{0}.lib", PythonType.ToLower())); + System.Console.WriteLine("Using Embedded Python at: " + PythonHome); + PublicIncludePaths.Add(PythonHome); + string libPath = Path.Combine(PythonHome, "Lib", string.Format("{0}.lib", PythonType.ToLower())); - System.Console.WriteLine("full lib path: " + libPath); - PublicLibraryPaths.Add(Path.GetDirectoryName(libPath)); - PublicAdditionalLibraries.Add(libPath); + System.Console.WriteLine("full lib path: " + libPath); + PublicLibraryPaths.Add(Path.GetDirectoryName(libPath)); + PublicAdditionalLibraries.Add(libPath); string dllPath = Path.Combine(BinariesPath, "Win64", string.Format("{0}.dll", PythonType.ToLower())); - RuntimeDependencies.Add(new RuntimeDependency(dllPath)); + RuntimeDependencies.Add(dllPath); } - else if (PythonHome == "") - { - pythonHome = DiscoverPythonPath(windowsKnownPaths, "Win64"); - if (pythonHome == "") - { - throw new System.Exception("Unable to find Python installation"); - } - - System.Console.WriteLine("Using Python at: " + PythonHome); - PublicIncludePaths.Add(PythonHome); - string libPath = GetWindowsPythonLibFile(PythonHome); - PublicLibraryPaths.Add(Path.GetDirectoryName(libPath)); - PublicAdditionalLibraries.Add(libPath); - } - } - - //other platforms - else + else if (PythonHome == "") + { + PythonHome = DiscoverPythonPath(windowsKnownPaths, "Win64"); + if (PythonHome == "") + { + throw new System.Exception("Unable to find Python installation"); + } + + System.Console.WriteLine("Using Python at: " + PythonHome); + PublicIncludePaths.Add(PythonHome); + string libPath = GetWindowsPythonLibFile(PythonHome); + PublicLibraryPaths.Add(Path.GetDirectoryName(libPath)); + PublicAdditionalLibraries.Add(libPath); + } + } + + //other platforms + else + { + if (PythonHome == "") + { + PythonHome = DiscoverPythonPath(macKnownPaths, "Mac"); + if (PythonHome == "") + { + throw new System.Exception("Unable to find Python installation"); + } + System.Console.WriteLine("Using Python at: " + PythonHome); + PublicIncludePaths.Add(PythonHome); + PublicAdditionalLibraries.Add(Path.Combine(PythonHome, "Lib", string.Format("{0}.lib", PythonType))); + } + System.Console.WriteLine("Using Python at: " + PythonHome); + PublicIncludePaths.Add(PythonHome); + string libPath = GetMacPythonLibFile(PythonHome); + PublicLibraryPaths.Add(Path.GetDirectoryName(libPath)); + PublicDelayLoadDLLs.Add(libPath); + } + if (Target.Platform == UnrealTargetPlatform.Linux) { if (PythonHome == "") - { - pythonHome = DiscoverPythonPath(macKnownPaths, "Mac"); - if (pythonHome == "") - { - throw new System.Exception("Unable to find Python installation"); - } - System.Console.WriteLine("Using Python at: " + PythonHome); - PublicIncludePaths.Add(PythonHome); - PublicAdditionalLibraries.Add(Path.Combine(PythonHome, "Lib", string.Format("{0}.lib", PythonType))); - } - System.Console.WriteLine("Using Python at: " + pythonHome); - PublicIncludePaths.Add(pythonHome); - string libPath = GetMacPythonLibFile(pythonHome); - PublicLibraryPaths.Add(Path.GetDirectoryName(libPath)); - PublicDelayLoadDLLs.Add(libPath); - } - else if (Target.Platform == UnrealTargetPlatform.Linux) - { - if (pythonHome == "") { string includesPath = DiscoverLinuxPythonIncludesPath(); if (includesPath == null) diff --git a/UnrealEnginePython.uplugin b/UnrealEnginePython.uplugin index 085171bac..348fed5f0 100644 --- a/UnrealEnginePython.uplugin +++ b/UnrealEnginePython.uplugin @@ -1,7 +1,7 @@ { "FileVersion": 3, "Version": 1, - "VersionName": "1.5.0", + "VersionName": "1.6.0", "FriendlyName": "UnrealEnginePython", "Description": "Embed a Python VM in your project", "Category": "Scripting Languages",