Просмотр исходного кода

Bugfix: Call managed object constructor when using ManagedSerializable types to create the objects

BearishSun 7 лет назад
Родитель
Сommit
5296be63cf

+ 2 - 3
Source/Scripting/SBansheeEngine/Serialization/BsManagedSerializableObject.cpp

@@ -80,9 +80,8 @@ namespace bs
 		if (!ScriptAssemblyManager::instance().getSerializableObjectInfo(type->mTypeNamespace, type->mTypeName, currentObjInfo))
 		if (!ScriptAssemblyManager::instance().getSerializableObjectInfo(type->mTypeNamespace, type->mTypeName, currentObjInfo))
 			return nullptr;
 			return nullptr;
 
 
-		// Never call constructor for structs. For classes we could call it if we could guarantee it always has one,
-		// but at the moment we don't call constructor for them at all (which is probably fine).
-		return currentObjInfo->mMonoClass->createInstance(false);
+		const bool construct = currentObjInfo->mMonoClass->getMethod(".ctor", 0) != nullptr;
+		return currentObjInfo->mMonoClass->createInstance(construct);
 	}
 	}
 
 
 	SPtr<ManagedSerializableObject> ManagedSerializableObject::createEmpty()
 	SPtr<ManagedSerializableObject> ManagedSerializableObject::createEmpty()