File tree Expand file tree Collapse file tree
Source/UnrealEnginePython Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,18 +39,21 @@ bool PyUnicodeOrString_Check(PyObject *py_obj) {
3939
4040void FUnrealEnginePythonModule::PythonGILRelease () {
4141#if UEPY_THREADING
42- if (PyGILState_Check ()) {
42+ if (PyGILState_Check () == 1 ) {
4343 ue_python_gil = PyEval_SaveThread ();
4444 }
4545#endif
4646}
4747
48- void FUnrealEnginePythonModule::PythonGILAcquire () {
48+ bool FUnrealEnginePythonModule::PythonGILAcquire () {
4949#if UEPY_THREADING
50- if (! PyGILState_Check ()) {
50+ if (PyGILState_Check () == 0 ) {
5151 PyEval_RestoreThread ((PyThreadState *)ue_python_gil);
52+ return true ;
5253 }
54+ return false ;
5355#endif
56+ return true ;
5457}
5558
5659void FUnrealEnginePythonModule::StartupModule ()
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class UNREALENGINEPYTHON_API FUnrealEnginePythonModule : public IModuleInterface
1111{
1212public:
1313
14- void PythonGILAcquire ();
14+ bool PythonGILAcquire ();
1515 void PythonGILRelease ();
1616
1717 virtual void StartupModule () override ;
@@ -32,18 +32,21 @@ struct FScopePythonGIL {
3232 {
3333#if UEPY_THREADING
3434 UnrealEnginePythonModule = FModuleManager::LoadModuleChecked<FUnrealEnginePythonModule>(" UnrealEnginePython" );
35- UnrealEnginePythonModule.PythonGILAcquire ();
35+ safeForRelease = UnrealEnginePythonModule.PythonGILAcquire ();
3636#endif
3737 }
3838
3939 ~FScopePythonGIL ()
4040 {
4141#if UEPY_THREADING
42- UnrealEnginePythonModule.PythonGILRelease ();
42+ if (safeForRelease) {
43+ UnrealEnginePythonModule.PythonGILRelease ();
44+ }
4345#endif
4446 }
4547
4648 FUnrealEnginePythonModule UnrealEnginePythonModule;
49+ bool safeForRelease;
4750};
4851
4952
You can’t perform that action at this time.
0 commit comments