@@ -16,11 +16,13 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
16
16
{
17
17
FWeakObjectPtr Owner;
18
18
ue_PyUObject *PyUObject;
19
+ bool bPythonOwned;
19
20
20
21
FPythonUOjectTracker (UObject *Object, ue_PyUObject *InPyUObject)
21
22
{
22
23
Owner = FWeakObjectPtr (Object);
23
24
PyUObject = InPyUObject;
25
+ bPythonOwned = false ;
24
26
}
25
27
};
26
28
@@ -110,6 +112,17 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
110
112
111
113
void TrackUObject (UObject *Object)
112
114
{
115
+ FPythonUOjectTracker *Tracker = UObjectPyMapping.Find (Object);
116
+ if (!Tracker)
117
+ {
118
+ return ;
119
+ }
120
+ if (Tracker->bPythonOwned )
121
+ return ;
122
+ Tracker->bPythonOwned = true ;
123
+ // when a new ue_PyUObject spawns, it has a reference counting of two
124
+ Py_DECREF (Tracker->PyUObject );
125
+ Tracker->PyUObject ->owned = 1 ;
113
126
PythonTrackedObjects.Add (Object);
114
127
}
115
128
@@ -141,14 +154,14 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
141
154
#if defined(UEPY_MEMORY_DEBUG)
142
155
UE_LOG (LogPython, Warning, TEXT (" DEFREF'ing UObject at %p (refcnt: %d)" ), Object, Tracker->PyUObject ->ob_base .ob_refcnt );
143
156
#endif
144
- if (!Tracker->PyUObject -> owned )
157
+ if (!Tracker->bPythonOwned )
145
158
Py_DECREF ((PyObject *)Tracker->PyUObject );
146
159
UnregisterPyUObject (Object);
147
160
return nullptr ;
148
- }
161
+ }
149
162
150
163
return Tracker->PyUObject ;
151
- }
164
+ }
152
165
153
166
uint32 PyUObjectsGC ()
154
167
{
@@ -168,19 +181,19 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
168
181
#endif
169
182
BrokenList.Add (Object);
170
183
Garbaged++;
171
- }
184
+ }
172
185
else
173
186
{
174
187
#if defined(UEPY_MEMORY_DEBUG)
175
188
UE_LOG (LogPython, Error, TEXT (" UObject at %p %s is in use" ), Object, *Object->GetName ());
176
189
#endif
177
- }
190
+ }
178
191
}
179
192
180
193
for (UObject *Object : BrokenList)
181
194
{
182
195
FPythonUOjectTracker &Tracker = UObjectPyMapping[Object];
183
- if (!Tracker.PyUObject -> owned )
196
+ if (!Tracker.bPythonOwned )
184
197
Py_DECREF ((PyObject *)Tracker.PyUObject );
185
198
UnregisterPyUObject (Object);
186
199
}
@@ -223,7 +236,7 @@ class FUnrealEnginePythonHouseKeeper : public FGCObject
223
236
224
237
}
225
238
return Garbaged;
226
- }
239
+ }
227
240
228
241
UPythonDelegate *NewDelegate (UObject *Owner, PyObject *PyCallable, UFunction *Signature)
229
242
{
0 commit comments