Skip to content

Commit d79be3a

Browse files
author
Roberto De Ioris
committed
fixed render_target_get_data()
1 parent 62de85b commit d79be3a

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎Source/UnrealEnginePython/Private/PyUserWidget.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,28 @@ UPyUserWidget::~UPyUserWidget()
328328
// this could trigger the distruction of the python/uobject mapper
329329
Py_XDECREF(py_uobject);
330330
}
331+
332+
void UPyUserWidget::CallPythonUserWidgetMethod(FString method_name, FString args)
333+
{
334+
if (!py_user_widget_instance)
335+
return;
336+
337+
FScopePythonGIL gil;
338+
339+
PyObject *ret = nullptr;
340+
if (args.IsEmpty())
341+
{
342+
ret = PyObject_CallMethod(py_user_widget_instance, TCHAR_TO_UTF8(*method_name), NULL);
343+
}
344+
else
345+
{
346+
ret = PyObject_CallMethod(py_user_widget_instance, TCHAR_TO_UTF8(*method_name), (char *)"s", TCHAR_TO_UTF8(*args));
347+
}
348+
349+
if (!ret)
350+
{
351+
unreal_engine_py_log_error();
352+
return;
353+
}
354+
Py_DECREF(ret);
355+
}

‎Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,27 @@ PyObject *py_ue_render_target_get_data(ue_PyUObject *self, PyObject * args)
110110
if (!tex)
111111
return PyErr_Format(PyExc_Exception, "object is not a TextureRenderTarget");
112112

113+
113114
FTextureRenderTarget2DResource *resource = (FTextureRenderTarget2DResource *)tex->Resource;
114115
if (!resource)
115116
{
116117
return PyErr_Format(PyExc_Exception, "cannot get render target resource");
117118
}
118119

119120
TArray<FColor> pixels;
121+
122+
if (!resource->IsSupportedFormat(tex->GetFormat()))
123+
{
124+
return PyErr_Format(PyExc_Exception, "unsupported format for render texture");
125+
}
126+
127+
120128
if (!resource->ReadPixels(pixels))
121129
{
122130
return PyErr_Format(PyExc_Exception, "unable to read pixels");
123131
}
124132

125-
return PyByteArray_FromStringAndSize((const char *)pixels.GetData(), (Py_ssize_t)(tex->GetSurfaceWidth() * 4 * tex->GetSurfaceHeight()));
133+
return PyByteArray_FromStringAndSize((const char *)pixels.GetData(), (Py_ssize_t)(pixels.GetTypeSize() * pixels.Num()));
126134
}
127135

128136
PyObject *py_ue_render_target_get_data_to_buffer(ue_PyUObject *self, PyObject * args)

‎Source/UnrealEnginePython/Public/PyUserWidget.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class UPyUserWidget : public UUserWidget
4444
UPROPERTY(EditAnywhere, Category = "Python", BlueprintReadWrite, meta = (ExposeOnSpawn = true))
4545
bool PythonPaintForceDisabled;
4646

47+
UFUNCTION(BlueprintCallable, Category = "Python")
48+
void CallPythonUserWidgetMethod(FString method_name, FString args);
49+
4750
private:
4851
PyObject *py_user_widget_instance;
4952
// mapped uobject, required for debug and advanced reflection

0 commit comments

Comments
 (0)