diff --git a/Source/Engine/AI/BehaviorKnowledge.cpp b/Source/Engine/AI/BehaviorKnowledge.cpp index a73a1cfd4..fce460636 100644 --- a/Source/Engine/AI/BehaviorKnowledge.cpp +++ b/Source/Engine/AI/BehaviorKnowledge.cpp @@ -144,7 +144,10 @@ BehaviorKnowledge::~BehaviorKnowledge() void BehaviorKnowledge::InitMemory(BehaviorTree* tree) { - ASSERT_LOW_LAYER(!Tree && tree); + if (Tree) + FreeMemory(); + if (!tree) + return; Tree = tree; Blackboard = Variant::NewValue(tree->Graph.Root->BlackboardType); RelevantNodes.Resize(tree->Graph.NodesCount, false); diff --git a/Source/Engine/Level/SceneObjectsFactory.cpp b/Source/Engine/Level/SceneObjectsFactory.cpp index 36681d64b..d9c86d250 100644 --- a/Source/Engine/Level/SceneObjectsFactory.cpp +++ b/Source/Engine/Level/SceneObjectsFactory.cpp @@ -445,6 +445,8 @@ void SceneObjectsFactory::SetupPrefabInstances(Context& context, const PrefabSyn const SceneObject* obj = data.SceneObjects[i]; const Guid id = obj ? obj->GetID() : JsonTools::GetGuid(stream, "ID"); auto prefab = Content::LoadAsync(prefabId); + if (!prefab) + continue; // Check if it's parent is in the same prefab int32 index; diff --git a/Source/Engine/Scripting/BinaryModule.cpp b/Source/Engine/Scripting/BinaryModule.cpp index e9465096f..44ef32503 100644 --- a/Source/Engine/Scripting/BinaryModule.cpp +++ b/Source/Engine/Scripting/BinaryModule.cpp @@ -1235,17 +1235,17 @@ bool ManagedBinaryModule::InvokeMethod(void* method, const Variant& instance, Sp const bool withInterfaces = !mMethod->IsStatic() && mMethod->GetParentClass()->IsInterface(); if (!mMethod->IsStatic()) { - // Box instance into C# object + // Box instance into C# object (and validate the type) MObject* instanceObject = MUtils::BoxVariant(instance); - const MClass* instanceObjectClass = MCore::Object::GetClass(instanceObject); - - // Validate instance - if (!instanceObject || !instanceObjectClass->IsSubClassOf(mMethod->GetParentClass(), withInterfaces)) + if (!instanceObject) { - if (!instanceObject) - LOG(Error, "Failed to call method '{0}.{1}' (args count: {2}) without object instance", String(mMethod->GetParentClass()->GetFullName()), String(mMethod->GetName()), parametersCount); - else - LOG(Error, "Failed to call method '{0}.{1}' (args count: {2}) with invalid object instance of type '{3}'", String(mMethod->GetParentClass()->GetFullName()), String(mMethod->GetName()), parametersCount, String(MUtils::GetClassFullname(instanceObject))); + LOG(Error, "Failed to call method '{0}.{1}' (args count: {2}) without object instance", String(mMethod->GetParentClass()->GetFullName()), String(mMethod->GetName()), parametersCount); + return true; + } + const MClass* instanceObjectClass = MCore::Object::GetClass(instanceObject); + if (!instanceObjectClass->IsSubClassOf(mMethod->GetParentClass(), withInterfaces)) + { + LOG(Error, "Failed to call method '{0}.{1}' (args count: {2}) with invalid object instance of type '{3}'", String(mMethod->GetParentClass()->GetFullName()), String(mMethod->GetName()), parametersCount, String(MUtils::GetClassFullname(instanceObject))); return true; }