Skip to content

Commit 4ce60ba

Browse files
committedFeb 18, 2019
backporting fixes from modus
1 parent 9426a02 commit 4ce60ba

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed
 

‎Source/UnrealEnginePython/Private/FMModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static PyObject *create_subclass(PyObject *self, PyObject *args)
227227
if (!pyInst)
228228
{
229229
LERROR("failed to instantiate python class");
230-
PyErr_Format(PyExc_Exception, "Failed to instantiate python clsas");
230+
PyErr_Format(PyExc_Exception, "Failed to instantiate python class");
231231
return;
232232
}
233233
pyObj->py_proxy = pyInst; // pyInst's ref is now owned by py_proxy. TODO: who decref's this later?

‎Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,12 +1181,10 @@ static void ue_pyobject_dealloc(ue_PyUObject *self)
11811181
#if defined(UEPY_MEMORY_DEBUG)
11821182
UE_LOG(LogPython, Warning, TEXT("Destroying ue_PyUObject %p mapped to UObject %p"), self, self->ue_object);
11831183
#endif
1184-
FUnrealEnginePythonHouseKeeper *housekeeper = FUnrealEnginePythonHouseKeeper::Get();
11851184
if (self->owned)
11861185
{
1187-
housekeeper->UntrackUObject(self->ue_object);
1186+
FUnrealEnginePythonHouseKeeper::Get()->UntrackUObject(self->ue_object);
11881187
}
1189-
housekeeper->UnregisterPyUObject(self->ue_object);
11901188

11911189
if (self->auto_rooted && (self->ue_object && self->ue_object->IsValidLowLevel() && self->ue_object->IsRooted()))
11921190
{
@@ -1329,7 +1327,9 @@ static int ue_PyUObject_setattro(ue_PyUObject *self, PyObject *attr_name, PyObje
13291327
{
13301328
#if WITH_EDITOR
13311329
if (!self->creating)
1332-
self->ue_object->PreEditChange(u_property);
1330+
{
1331+
self->ue_object->PreEditChange(u_property);
1332+
}
13331333
#endif
13341334
if (ue_py_convert_pyobject(value, u_property, (uint8*)self->ue_object, 0))
13351335
{
@@ -1874,10 +1874,7 @@ ue_PyUObject *ue_get_python_uobject(UObject *ue_obj)
18741874
ue_py_object->py_dict = PyDict_New();
18751875
ue_py_object->owned = 0;
18761876

1877-
FUnrealEnginePythonHouseKeeper *housekeeper = FUnrealEnginePythonHouseKeeper::Get();
1878-
housekeeper->RegisterPyUObject(ue_obj, ue_py_object);
1879-
Py_INCREF(ue_py_object); // this is needed only because the following decrefs it
1880-
housekeeper->TrackUObject(ue_obj);
1877+
FUnrealEnginePythonHouseKeeper::Get()->RegisterPyUObject(ue_obj, ue_py_object);
18811878

18821879
#if defined(UEPY_MEMORY_DEBUG)
18831880
UE_LOG(LogPython, Warning, TEXT("CREATED UPyObject at %p for %p %s"), ue_py_object, ue_obj, *ue_obj->GetName());

‎Source/UnrealEnginePython/Public/FMPythonClass.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ void UFMPythonClass::CallPyConstructor(ue_PyUObject *self)
2020
}
2121

2222

23+
UObject* UFMPythonClass::CreateDefaultObject()
24+
{
25+
bool savedLoad = GIsInitialLoad;
26+
27+
// this is a total hack but be need to go around the default
28+
// package loading logic when loading default objects
29+
GIsInitialLoad = false;
30+
UObject *ret = Super::CreateDefaultObject();
31+
GIsInitialLoad = savedLoad;
32+
33+
return ret;
34+
}

‎Source/UnrealEnginePython/Public/FMPythonClass.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class UFMPythonClass : public UClass
2222
// true while we're creating this class (including the stuff in Python)
2323
bool creating;
2424

25+
protected:
26+
virtual UObject* CreateDefaultObject() override;
27+
2528
private:
2629

2730
PyObject * py_constructor;

‎Source/UnrealEnginePython/Public/PythonHouseKeeper.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
167167
{
168168
uint32 Garbaged = 0;
169169
TArray<UObject *> BrokenList;
170-
TArray<ue_PyUObject *> needDecRef;
171170
for (auto &UObjectPyItem : UObjectPyMapping)
172171
{
173172
UObject *Object = UObjectPyItem.Key;
@@ -183,26 +182,14 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
183182
BrokenList.Add(Object);
184183
Garbaged++;
185184
}
186-
else if (Tracker.PyUObject->ob_base.ob_refcnt == 1)
187-
{ // the tracker is the only thing keeping this alive, so release the last reference
188-
#if defined(UEPY_MEMORY_DEBUG)
189-
UE_LOG(LogPython, Warning, TEXT("Auto-decrefing UObject at %p %s"), Object, *Object->GetName());
190-
#endif
191-
needDecRef.Add(Tracker.PyUObject);
192-
}
193185
else
194186
{
195187
#if defined(UEPY_MEMORY_DEBUG)
196-
UE_LOG(LogPython, Error, TEXT("UObject at %p %s is in use, py ref count %d"), Object, *Object->GetName(), Tracker.PyUObject->ob_base.ob_refcnt);
188+
UE_LOG(LogPython, Error, TEXT("UObject at %p %s is in use"), Object, *Object->GetName());
197189
#endif
198190
}
199191
}
200192

201-
for (ue_PyUObject *py_obj : needDecRef)
202-
{
203-
Py_DECREF(py_obj); // on the next GC run, this object will dealloc and unregister itself
204-
}
205-
206193
for (UObject *Object : BrokenList)
207194
{
208195
FPythonUOjectTracker &Tracker = UObjectPyMapping[Object];

0 commit comments

Comments
 (0)
Failed to load comments.