Skip to content

Commit ff24810

Browse files
author
Roberto De Ioris
committed
added PythonHouseKeeper class
1 parent 8a93833 commit ff24810

12 files changed

Lines changed: 422 additions & 263 deletions

‎Source/UnrealEnginePython/Private/PyActor.cpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void APyActor::PreInitializeComponents()
7070

7171
PyObject_SetAttrString(py_actor_instance, (char*)"uobject", (PyObject *)py_uobject);
7272

73+
7374
if (!PyObject_HasAttrString(py_actor_instance, (char *)"tick") || PythonTickForceDisabled)
7475
{
7576
SetActorTickEnabled(false);
@@ -80,6 +81,7 @@ void APyActor::PreInitializeComponents()
8081

8182
ue_bind_events_for_py_class_by_attribute(this, py_actor_instance);
8283

84+
8385
if (!PyObject_HasAttrString(py_actor_instance, (char *)"pre_initialize_components"))
8486
return;
8587

@@ -134,6 +136,7 @@ void APyActor::BeginPlay()
134136
return;
135137
}
136138
Py_DECREF(bp_ret);
139+
137140
}
138141

139142

@@ -179,6 +182,8 @@ void APyActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
179182
Py_XDECREF(ep_ret);
180183
}
181184

185+
186+
182187
Super::EndPlay(EndPlayReason);
183188

184189
// ...
@@ -296,10 +301,9 @@ APyActor::~APyActor()
296301
UE_LOG(LogPython, Warning, TEXT("Python AActor %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->py_proxy : nullptr);
297302
#endif
298303

299-
// this could trigger the destruction of the python/uobject mapper
300-
if (py_uobject)
301-
{
302-
UE_LOG(LogPython, Error, TEXT("UObject refcnt = %d"), py_uobject->ob_base.ob_refcnt);
303-
}
304+
304305
Py_XDECREF(py_uobject);
306+
FUnrealEnginePythonHouseKeeper::Get()->UnregisterPyUObject(this);
307+
308+
305309
}

‎Source/UnrealEnginePython/Private/PythonDelegate.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void UPythonDelegate::SetPyCallable(PyObject *callable)
1212
// do not acquire the gil here as we set the callable in python call themselves
1313
py_callable = callable;
1414
Py_INCREF(py_callable);
15+
UE_LOG(LogPython, Error, TEXT("CALLABLE %d"), py_callable->ob_refcnt);
1516
}
1617

1718
void UPythonDelegate::SetSignature(UFunction *original_signature)
@@ -104,6 +105,11 @@ void UPythonDelegate::PyInputAxisHandler(float value)
104105
UPythonDelegate::~UPythonDelegate()
105106
{
106107
FScopePythonGIL gil;
108+
109+
if (py_callable)
110+
{
111+
UE_LOG(LogPython, Error, TEXT("DELEGATE N %d\n"), py_callable->ob_refcnt);
112+
}
107113
Py_XDECREF(py_callable);
108114
#if defined(UEPY_MEMORY_DEBUG)
109115
UE_LOG(LogPython, Warning, TEXT("PythonDelegate callable XDECREF'ed"));

‎Source/UnrealEnginePython/Private/UEPyEngine.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ PyObject *py_unreal_engine_new_object(PyObject * self, PyObject * args)
511511
PyObject *obj;
512512
PyObject *py_outer = NULL;
513513
char *name = nullptr;
514-
uint64 flags = (uint64)(RF_Public | RF_Standalone);
514+
uint64 flags = (uint64)(RF_Public);
515515
if (!PyArg_ParseTuple(args, "O|OsK:new_object", &obj, &py_outer, &name, &flags))
516516
{
517517
return NULL;

0 commit comments

Comments
 (0)