Skip to content

Fix the problem which multiscrpit_delegate causes engine crash #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
974 changes: 8 additions & 966 deletions README.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Source/UnrealEnginePython/Private/Http/UEPyIHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ static int ue_py_ihttp_request_init(ue_PyIHttpRequest *self, PyObject *args, PyO
{
return -1;
}
#if ENGINE_MINOR_VERSION == 27
new(&self->http_request) TSharedRef<IHttpRequest, ESPMode::ThreadSafe>(FHttpModule::Get().CreateRequest());
#elif ENGINE_MINOR_VERSION == 26
new(&self->http_request) TSharedRef<IHttpRequest, ESPMode::ThreadSafe>(FHttpModule::Get().CreateRequest());
#else
new(&self->http_request) TSharedRef<IHttpRequest>(FHttpModule::Get().CreateRequest());
#endif
new(&self->on_process_request_complete) TSharedPtr<FPythonSmartHttpDelegate>(nullptr);
new(&self->on_request_progress) TSharedPtr<FPythonSmartHttpDelegate>(nullptr);
self->py_dict = PyDict_New();
Expand Down
13 changes: 12 additions & 1 deletion Source/UnrealEnginePython/Private/Slate/UEPySCheckBox.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "UEPySCheckBox.h"
#include "UEPySCheckBox.h"


static PyObject *py_ue_scheck_box_is_checked(ue_PySCheckBox *self, PyObject * args)
Expand Down Expand Up @@ -103,7 +103,18 @@ static int ue_py_scheck_box_init(ue_PySCheckBox *self, PyObject *args, PyObject
ue_py_slate_farguments_enum("is_checked", IsChecked, ECheckBoxState);
ue_py_slate_farguments_optional_enum("h_align", HAlign, EHorizontalAlignment);
ue_py_slate_farguments_struct("padding", Padding, FMargin);
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
//#pragma message("need more information!! mutable .... thing")
#ifndef UE_BUILD_DEBUG
#error "TODO: "
#else
#pragma message(" ====================================================== WARNING! ACHTUNG! Atención! ================================================")
#pragma message("\t\tue_py_slate_farguments_enum(\"click_method\", ClickMethod, EButtonClickMethod::Type); // ")
#pragma message(" ====================================================== WARNING! ACHTUNG! Atención! ================================================")
#endif
#else
ue_py_slate_farguments_enum("click_method", ClickMethod, EButtonClickMethod::Type);
#endif
ue_py_slate_farguments_optional_bool("is_focusable", IsFocusable);
ue_py_slate_farguments_optional_struct_ptr("unchecked_image", UncheckedImage, FSlateBrush);
ue_py_slate_farguments_optional_struct_ptr("unchecked_hoveredimage", UncheckedHoveredImage, FSlateBrush);
Expand Down
4 changes: 4 additions & 0 deletions Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,11 @@ PyObject *py_unreal_engine_invoke_tab(PyObject * self, PyObject * args)
return NULL;
}

#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
FGlobalTabmanager::Get()->TryInvokeTab(FTabId(FName(UTF8_TO_TCHAR(name))));
#else
FGlobalTabmanager::Get()->InvokeTab(FTabId(FName(UTF8_TO_TCHAR(name))));
#endif

Py_INCREF(Py_None);
return Py_None;
Expand Down
34 changes: 29 additions & 5 deletions Source/UnrealEnginePython/Private/UEPyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ PyObject *py_unreal_engine_create_asset(PyObject * self, PyObject * args)
PyObject *py_unreal_engine_get_asset_referencers(PyObject * self, PyObject * args)
{
char *path;

int depency_type = (int)EAssetRegistryDependencyType::All;

if (!PyArg_ParseTuple(args, "s|i:get_asset_referencers", &path, &depency_type))
Expand All @@ -688,7 +689,11 @@ PyObject *py_unreal_engine_get_asset_referencers(PyObject * self, PyObject * arg

FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
TArray<FName> referencers;
AssetRegistryModule.Get().GetReferencers(UTF8_TO_TCHAR(path), referencers, (EAssetRegistryDependencyType::Type) depency_type);



AssetRegistryModule.Get().GetReferencers(UTF8_TO_TCHAR(path), referencers, (EAssetRegistryDependencyType::Type)depency_type);


PyObject *referencers_list = PyList_New(0);
for (FName name : referencers)
Expand Down Expand Up @@ -1346,7 +1351,11 @@ PyObject *py_unreal_engine_create_blueprint(PyObject * self, PyObject * args)
return PyErr_Format(PyExc_Exception, "invalid blueprint name");
}

UPackage *outer = CreatePackage(nullptr, UTF8_TO_TCHAR(name));
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
UPackage *outer = CreatePackage(UTF8_TO_TCHAR(name));
#else
UPackage* outer = CreatePackage(nullptr, UTF8_TO_TCHAR(name));
#endif
if (!outer)
return PyErr_Format(PyExc_Exception, "unable to create package");

Expand Down Expand Up @@ -1508,7 +1517,14 @@ PyObject *py_unreal_engine_create_blueprint_from_actor(PyObject * self, PyObject
return PyErr_Format(PyExc_Exception, "uobject is not a UClass");
AActor *actor = (AActor *)py_obj->ue_object;

UBlueprint *bp = FKismetEditorUtilities::CreateBlueprintFromActor(UTF8_TO_TCHAR(name), actor, true);
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
FKismetEditorUtilities::FCreateBlueprintFromActorParams Params;
Params.bReplaceActor = true;

UBlueprint* bp = FKismetEditorUtilities::CreateBlueprintFromActor( *FString( UTF8_TO_TCHAR(name) ), actor, Params);
#else
UBlueprint* bp = FKismetEditorUtilities::CreateBlueprintFromActor(UTF8_TO_TCHAR(name), actor, true);
#endif

Py_RETURN_UOBJECT(bp);
}
Expand Down Expand Up @@ -2089,7 +2105,11 @@ PyObject *py_ue_factory_create_new(ue_PyUObject *self, PyObject * args)
FString PackageName = PackageTools::SanitizePackageName(FString(UTF8_TO_TCHAR(name)));
#endif

UPackage *outer = CreatePackage(nullptr, *PackageName);
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
UPackage* outer = CreatePackage(*PackageName);
#else
UPackage* outer = CreatePackage(nullptr, *PackageName);
#endif
if (!outer)
return PyErr_Format(PyExc_Exception, "unable to create package");

Expand Down Expand Up @@ -2161,7 +2181,11 @@ PyObject *py_ue_factory_import_object(ue_PyUObject *self, PyObject * args)
FString object_name = ObjectTools::SanitizeObjectName(FPaths::GetBaseFilename(UTF8_TO_TCHAR(filename)));
FString pkg_name = FString(UTF8_TO_TCHAR(name)) + TEXT("/") + object_name;

UPackage *outer = CreatePackage(nullptr, *pkg_name);
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
UPackage* outer = CreatePackage(*pkg_name);
#else
UPackage* outer = CreatePackage(nullptr, *pkg_name);
#endif
if (!outer)
return PyErr_Format(PyExc_Exception, "unable to create package");

Expand Down
10 changes: 9 additions & 1 deletion Source/UnrealEnginePython/Private/UEPyEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ PyObject *py_unreal_engine_object_path_to_package_name(PyObject * self, PyObject
{
return NULL;
}
return PyUnicode_FromString(TCHAR_TO_UTF8(*FPackageName::ObjectPathToPackageName(UTF8_TO_TCHAR(path))));
return PyUnicode_FromString(TCHAR_TO_UTF8(*FPackageName::ObjectPathToPackageName( FString( UTF8_TO_TCHAR(path) ) )));
}

PyObject *py_unreal_engine_get_path(PyObject * self, PyObject * args)
Expand Down Expand Up @@ -1057,7 +1057,11 @@ PyObject *py_unreal_engine_create_package(PyObject *self, PyObject * args)
{
return PyErr_Format(PyExc_Exception, "package %s already exists", TCHAR_TO_UTF8(*u_package->GetPathName()));
}
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
u_package = CreatePackage(UTF8_TO_TCHAR(name));
#else
u_package = CreatePackage(nullptr, UTF8_TO_TCHAR(name));
#endif
if (!u_package)
return PyErr_Format(PyExc_Exception, "unable to create package");
u_package->FileName = *FPackageName::LongPackageNameToFilename(UTF8_TO_TCHAR(name), FPackageName::GetAssetPackageExtension());
Expand All @@ -1082,7 +1086,11 @@ PyObject *py_unreal_engine_get_or_create_package(PyObject *self, PyObject * args
// create a new package if it does not exist
if (!u_package)
{
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
u_package = CreatePackage(UTF8_TO_TCHAR(name));
#else
u_package = CreatePackage(nullptr, UTF8_TO_TCHAR(name));
#endif
if (!u_package)
return PyErr_Format(PyExc_Exception, "unable to create package");
u_package->FileName = *FPackageName::LongPackageNameToFilename(UTF8_TO_TCHAR(name), FPackageName::GetAssetPackageExtension());
Expand Down
25 changes: 13 additions & 12 deletions Source/UnrealEnginePython/Private/UEPyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4460,16 +4460,16 @@ PyObject* ue_bind_pyevent(ue_PyUObject* u_obj, FString event_name, PyObject* py_
}

#if ENGINE_MINOR_VERSION >= 25
if (auto casted_prop = CastField<FMulticastDelegateProperty>(f_property))
if (auto casted_prop = Cast<UMulticastDelegateProperty>(f_property))
#else
if (auto casted_prop = Cast<UMulticastDelegateProperty>(u_property))
#endif
{
#if ENGINE_MINOR_VERSION < 23
FMulticastScriptDelegate multiscript_delegate = casted_prop->GetPropertyValue_InContainer(u_obj->ue_object);
#else
FMulticastScriptDelegate multiscript_delegate = *casted_prop->GetMulticastDelegate(u_obj->ue_object);
#endif
//#if ENGINE_MINOR_VERSION < 23
// FMulticastScriptDelegate multiscript_delegate = casted_prop->GetPropertyValue_InContainer(u_obj->ue_object);
//#else
// FMulticastScriptDelegate multiscript_delegate = *casted_prop->GetMulticastDelegate(u_obj->ue_object);
//#endif

FScriptDelegate script_delegate;
#if ENGINE_MINOR_VERSION >= 25
Expand All @@ -4482,14 +4482,15 @@ PyObject* ue_bind_pyevent(ue_PyUObject* u_obj, FString event_name, PyObject* py_
script_delegate.BindUFunction(py_delegate, FName("PyFakeCallable"));

// add the new delegate
multiscript_delegate.Add(script_delegate);
//multiscript_delegate.Add(script_delegate);
casted_prop->AddDelegate(script_delegate, u_obj->ue_object);

// re-assign multicast delegate
#if ENGINE_MINOR_VERSION < 23
casted_prop->SetPropertyValue_InContainer(u_obj->ue_object, multiscript_delegate);
#else
casted_prop->SetMulticastDelegate(u_obj->ue_object, multiscript_delegate);
#endif
//#if ENGINE_MINOR_VERSION < 23
// casted_prop->SetPropertyValue_InContainer(u_obj->ue_object, multiscript_delegate);
//#else
// casted_prop->SetMulticastDelegate(u_obj->ue_object, multiscript_delegate);
//#endif
}
#if ENGINE_MINOR_VERSION >= 25
else if (auto casted_prop_delegate = CastField<FDelegateProperty>(f_property))
Expand Down
4 changes: 4 additions & 0 deletions Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,11 @@ PyObject *py_ue_save_package(ue_PyUObject * self, PyObject * args)
}
}
// create a new package if it does not exist
#if ENGINE_MINOR_VERSION == 27 || ENGINE_MINOR_VERSION == 26
package = CreatePackage(UTF8_TO_TCHAR(name));
#else
package = CreatePackage(nullptr, UTF8_TO_TCHAR(name));
#endif
if (!package)
return PyErr_Format(PyExc_Exception, "unable to create package");

Expand Down
17 changes: 16 additions & 1 deletion Source/UnrealEnginePython/Private/UObject/UEPySequencer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "UEPySequencer.h"
#include "UEPySequencer.h"

#include "Runtime/MovieScene/Public/MovieScene.h"
#include "Runtime/MovieScene/Public/MovieScenePossessable.h"
Expand Down Expand Up @@ -601,7 +601,11 @@ PyObject *py_ue_sequencer_add_camera(ue_PyUObject *self, PyObject * args)
// Lock the viewport to this camera
if (NewCamera && NewCamera->GetLevel())
{
#if ENGINE_MINOR_VERSION == 27
GCurrentLevelEditingViewportClient->SetCinematicActorLock(nullptr);
#else
GCurrentLevelEditingViewportClient->SetMatineeActorLock(nullptr);
#endif
GCurrentLevelEditingViewportClient->SetActorLock(NewCamera);
GCurrentLevelEditingViewportClient->bLockedCameraView = true;
GCurrentLevelEditingViewportClient->UpdateViewForLockedActor();
Expand All @@ -611,7 +615,18 @@ PyObject *py_ue_sequencer_add_camera(ue_PyUObject *self, PyObject * args)
UMovieSceneSequence* Sequence = sequencer->GetFocusedMovieSceneSequence();
UMovieScene* OwnerMovieScene = Sequence->GetMovieScene();

#if ENGINE_MINOR_VERSION == 27
#ifndef UE_BUILD_DEBUG
#error "don't compile it for production'"
#else
//MovieSceneToolHelpers::CameraAdded(OwnerMovieScene, CameraGuid, sequencer->GetLocalTime().Time.FloorToFrame());
#pragma message(" ====================================================== WARNING! ACHTUNG! Atención! ================================================")
#pragma message("\t\tMovieSceneToolHelpers::CameraAdded(OwnerMovieScene, CameraGuid, sequencer->GetLocalTime().Time.FloorToFrame());")
#pragma message(" ====================================================== WARNING! ACHTUNG! Atención! ================================================")
#endif
#else
MovieSceneToolHelpers::CameraAdded(OwnerMovieScene, CameraGuid, sequencer->GetLocalTime().Time.FloorToFrame());
#endif

}
#else
Expand Down
46 changes: 46 additions & 0 deletions Source/UnrealEnginePython/Private/UObject/UEPySkeletal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,14 @@ PyObject *py_ue_skeletal_mesh_set_soft_vertices(ue_PyUObject *self, PyObject * a
model.Sections[section_index].NumVertices = soft_vertices.Num();
model.Sections[section_index].CalcMaxBoneInfluences();

#if ENGINE_MINOR_VERSION == 27
mesh->GetRefBasesInvMatrix().Empty();
#else
mesh->RefBasesInvMatrix.Empty();
#endif
mesh->CalculateInvRefMatrices();


#if WITH_EDITOR
mesh->PostEditChange();
#endif
Expand Down Expand Up @@ -468,11 +473,18 @@ PyObject *py_ue_skeletal_mesh_set_skeleton(ue_PyUObject * self, PyObject * args)
mesh->ReleaseResources();
mesh->ReleaseResourcesFence.Wait();

#if ENGINE_MINOR_VERSION == 27
mesh->SetSkeleton( skeleton );
mesh->SetRefSkeleton( skeleton->GetReferenceSkeleton() );
mesh->GetRefBasesInvMatrix().Empty();
#else
mesh->Skeleton = skeleton;

mesh->RefSkeleton = skeleton->GetReferenceSkeleton();

mesh->RefBasesInvMatrix.Empty();
#endif

mesh->CalculateInvRefMatrices();

#if WITH_EDITOR
Expand Down Expand Up @@ -548,7 +560,12 @@ PyObject *py_ue_skeletal_mesh_set_bone_map(ue_PyUObject *self, PyObject * args)

model.Sections[section_index].BoneMap = bone_map;

#if ENGINE_MINOR_VERSION == 27
mesh->GetRefBasesInvMatrix().Empty();
#else
mesh->RefBasesInvMatrix.Empty();
#endif

mesh->CalculateInvRefMatrices();

#if WITH_EDITOR
Expand Down Expand Up @@ -701,7 +718,12 @@ PyObject *py_ue_skeletal_mesh_set_active_bone_indices(ue_PyUObject *self, PyObje
model.ActiveBoneIndices = active_indices;
model.ActiveBoneIndices.Sort();

#if ENGINE_MINOR_VERSION == 27
mesh->GetRefBasesInvMatrix().Empty();
#else
mesh->RefBasesInvMatrix.Empty();
#endif

mesh->CalculateInvRefMatrices();

#if WITH_EDITOR
Expand Down Expand Up @@ -810,7 +832,11 @@ PyObject *py_ue_skeletal_mesh_set_required_bones(ue_PyUObject *self, PyObject *
model.RequiredBones = required_bones;
model.RequiredBones.Sort();

#if ENGINE_MINOR_VERSION == 27
mesh->GetRefBasesInvMatrix().Empty();
#else
mesh->RefBasesInvMatrix.Empty();
#endif
mesh->CalculateInvRefMatrices();

#if WITH_EDITOR
Expand Down Expand Up @@ -1065,7 +1091,13 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args, PyO
build_settings.bComputeTangents = (py_compute_tangents && PyObject_IsTrue(py_compute_tangents));
build_settings.bRemoveDegenerateTriangles = true;

#if ENGINE_MINOR_VERSION == 27
bool success = MeshUtilities.BuildSkeletalMesh(lod_model, mesh->GetName(), mesh->GetRefSkeleton(), influences, wedges, faces, points, points_to_map, build_settings);
#elif ENGINE_MINOR_VERSION == 26
bool success = MeshUtilities.BuildSkeletalMesh(lod_model, mesh->GetName(), mesh->RefSkeleton, influences, wedges, faces, points, points_to_map, build_settings);
#else
bool success = MeshUtilities.BuildSkeletalMesh(lod_model, mesh->RefSkeleton, influences, wedges, faces, points, points_to_map, build_settings);
#endif

if (!success)
{
Expand All @@ -1079,17 +1111,31 @@ PyObject *py_ue_skeletal_mesh_build_lod(ue_PyUObject *self, PyObject * args, PyO
}
#endif

#if ENGINE_MINOR_VERSION == 27
mesh->CalculateRequiredBones(LODModel, mesh->GetRefSkeleton(), nullptr);
#else
mesh->CalculateRequiredBones(LODModel, mesh->RefSkeleton, nullptr);
#endif
mesh->CalculateInvRefMatrices();

#if ENGINE_MINOR_VERSION == 27
mesh->GetSkeleton()->RecreateBoneTree(mesh);
mesh->GetSkeleton()->SetPreviewMesh(mesh);
#else
mesh->Skeleton->RecreateBoneTree(mesh);
mesh->Skeleton->SetPreviewMesh(mesh);
#endif

// calculate bounds from points
mesh->SetImportedBounds(FBoxSphereBounds(points.GetData(), points.Num()));

#if ENGINE_MINOR_VERSION == 27
mesh->GetSkeleton()->PostEditChange();
mesh->GetSkeleton()->MarkPackageDirty();
#else
mesh->Skeleton->PostEditChange();
mesh->Skeleton->MarkPackageDirty();
#endif

mesh->PostEditChange();
mesh->MarkPackageDirty();
Expand Down
15 changes: 15 additions & 0 deletions Source/UnrealEnginePython/Private/Voice/UEPyIVoiceCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,22 @@ static PyTypeObject ue_PyIVoiceCaptureType = {
static int py_ue_ivoice_capture_init(ue_PyIVoiceCapture *self, PyObject * args)
{

#if ENGINE_MINOR_VERSION == 27
#ifdef UE_BUILD_DEBUG
TSharedPtr<IVoiceCapture> voice_capture_ptr = FVoiceModule::Get().CreateVoiceCapture("", 44100, 16);
#else
#error "At first change this record"
#endif
#elif ENGINE_MINOR_VERSION == 26
#ifdef UE_BUILD_DEBUG
TSharedPtr<IVoiceCapture> voice_capture_ptr = FVoiceModule::Get().CreateVoiceCapture("", 44100, 16);
#else
#error "At first change this record"
#endif
#else
TSharedPtr<IVoiceCapture> voice_capture_ptr = FVoiceModule::Get().CreateVoiceCapture();
#endif

if (!voice_capture_ptr.IsValid())
{
PyErr_SetString(PyExc_Exception, "unable to create a new VoiceCapture");
Expand Down
Loading