@@ -148,8 +148,7 @@ static PyObject *py_ue_get_py_proxy(ue_PyUObject *self, PyObject * args)
148148 return (PyObject *)self->py_proxy ;
149149 }
150150
151- Py_INCREF (Py_None);
152- return Py_None;
151+ Py_RETURN_NONE;
153152}
154153
155154static PyMethodDef unreal_engine_methods[] = {
@@ -982,6 +981,7 @@ void ue_pydelegates_cleanup(ue_PyUObject *self)
982981 // start deallocating delegates mapped to the object
983982 if (!self || !self->python_delegates_gc )
984983 return ;
984+ UE_LOG (LogPython, Warning, TEXT (" Delegates = %d" ), self->python_delegates_gc ->size ());
985985 for (UPythonDelegate *py_delegate : *(self->python_delegates_gc ))
986986 {
987987 if (py_delegate && py_delegate->IsValidLowLevel ())
@@ -2096,7 +2096,7 @@ void unreal_engine_init_py_module()
20962096
20972097// utility functions
20982098
2099- ue_PyUObject *ue_get_python_wrapper (UObject *ue_obj)
2099+ ue_PyUObject *ue_get_python_uobject (UObject *ue_obj)
21002100{
21012101 if (!ue_obj || !ue_obj->IsValidLowLevel () || ue_obj->IsPendingKillOrUnreachable ())
21022102 return nullptr ;
@@ -2122,10 +2122,20 @@ ue_PyUObject *ue_get_python_wrapper(UObject *ue_obj)
21222122 // Py_INCREF(ue_py_object);
21232123 return ue_py_object;
21242124 }
2125-
2125+ Py_INCREF (it-> second );
21262126 return it->second ;
21272127}
21282128
2129+ ue_PyUObject *ue_get_python_uobject_noinc (UObject *ue_obj)
2130+ {
2131+ ue_PyUObject *ret = ue_get_python_uobject (ue_obj);
2132+ if (ret)
2133+ {
2134+ Py_DECREF (ret);
2135+ }
2136+ return ret;
2137+ }
2138+
21292139void unreal_engine_py_log_error ()
21302140{
21312141 PyObject *type = NULL ;
@@ -2327,11 +2337,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
23272337 auto value = casted_prop->GetObjectPropertyValue_InContainer (buffer);
23282338 if (value)
23292339 {
2330- ue_PyUObject *ret = ue_get_python_wrapper (value);
2331- if (!ret)
2332- return PyErr_Format (PyExc_Exception, " uobject is in invalid state" );
2333- Py_INCREF (ret);
2334- return (PyObject *)ret;
2340+ Py_RETURN_UOBJECT (value);
23352341 }
23362342 Py_RETURN_NONE;
23372343 }
@@ -2341,11 +2347,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
23412347 auto value = casted_prop->GetPropertyValue_InContainer (buffer);
23422348 if (value)
23432349 {
2344- ue_PyUObject *ret = ue_get_python_wrapper (value);
2345- if (!ret)
2346- return PyErr_Format (PyExc_Exception, " uobject is in invalid state" );
2347- Py_INCREF (ret);
2348- return (PyObject *)ret;
2350+ Py_RETURN_UOBJECT (value);
23492351 }
23502352 return PyErr_Format (PyExc_Exception, " invalid UClass type for %s" , TCHAR_TO_UTF8 (*casted_prop->GetName ()));
23512353 }
@@ -2397,11 +2399,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
23972399 UObject *strong_obj = value.Get ();
23982400 if (strong_obj)
23992401 {
2400- ue_PyUObject *ret = ue_get_python_wrapper (strong_obj);
2401- if (!ret)
2402- return PyErr_Format (PyExc_Exception, " uobject is in invalid state" );
2403- Py_INCREF (ret);
2404- return (PyObject *)ret;
2402+ Py_RETURN_UOBJECT (strong_obj);
24052403 }
24062404 // nullptr
24072405 Py_INCREF (Py_None);
@@ -2410,11 +2408,7 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer)
24102408
24112409 if (auto casted_prop = Cast<UMulticastDelegateProperty>(prop))
24122410 {
2413- ue_PyUObject *ret = ue_get_python_wrapper (casted_prop);
2414- if (!ret)
2415- return PyErr_Format (PyExc_Exception, " uobject is in invalid state" );
2416- Py_INCREF (ret);
2417- return (PyObject *)ret;
2411+ Py_RETURN_UOBJECT (casted_prop);
24182412 }
24192413
24202414 if (auto casted_prop = Cast<UArrayProperty>(prop))
@@ -2967,7 +2961,7 @@ void ue_bind_events_for_py_class_by_attribute(UObject *u_obj, PyObject *py_class
29672961 {
29682962 if (n == 1 )
29692963 {
2970- if (!ue_bind_pyevent (ue_get_python_wrapper (actor), parts[0 ], item, true ))
2964+ if (!ue_bind_pyevent (ue_get_python_uobject (actor), parts[0 ], item, true ))
29712965 {
29722966 unreal_engine_py_log_error ();
29732967 }
@@ -3234,8 +3228,7 @@ PyObject *ue_bind_pyevent(ue_PyUObject *u_obj, FString event_name, PyObject *py_
32343228 {
32353229 if (fail_on_wrong_property)
32363230 return PyErr_Format (PyExc_Exception, " unable to find event property %s" , TCHAR_TO_UTF8 (*event_name));
3237- Py_INCREF (Py_None);
3238- return Py_None;
3231+ Py_RETURN_NONE;
32393232 }
32403233
32413234 if (auto casted_prop = Cast<UMulticastDelegateProperty>(u_property))
@@ -3265,8 +3258,7 @@ PyObject *ue_bind_pyevent(ue_PyUObject *u_obj, FString event_name, PyObject *py_
32653258 return PyErr_Format (PyExc_Exception, " property %s is not an event" , TCHAR_TO_UTF8 (*event_name));
32663259 }
32673260
3268- Py_INCREF (Py_None);
3269- return Py_None;
3261+ Py_RETURN_NONE;
32703262}
32713263
32723264UFunction *unreal_engine_add_function (UClass *u_class, char *name, PyObject *py_callable, uint32 function_flags)
0 commit comments