Browse Source

No longer call constructor after managed object deserialization (no guarantees the class will have one)
More fixes to physics joint deserialization

BearishSun 9 năm trước cách đây
mục cha
commit
7074585593

+ 1 - 1
Source/MBansheeEngine/Physics/Interop/NativeJoint.cs

@@ -96,7 +96,7 @@ namespace BansheeEngine
     /// <summary>
     /// <summary>
     /// Used for passing common Joint initialization data between native and managed code.
     /// Used for passing common Joint initialization data between native and managed code.
     /// </summary>
     /// </summary>
-    [StructLayout(LayoutKind.Sequential)]
+    [StructLayout(LayoutKind.Sequential), SerializeObject]
     internal struct ScriptCommonJointData // Note: Must match C++ struct ScriptCommonJointData
     internal struct ScriptCommonJointData // Note: Must match C++ struct ScriptCommonJointData
     {
     {
         public IntPtr[] bodies;
         public IntPtr[] bodies;

+ 2 - 3
Source/MBansheeEngine/Physics/Joint.cs

@@ -267,8 +267,8 @@ namespace BansheeEngine
         /// </summary>
         /// </summary>
         private void RestoreNative()
         private void RestoreNative()
         {
         {
-            [email protected][0] = IntPtr.Zero;
-            [email protected][1] = IntPtr.Zero;
+            // Make sure to always create a new instance of this array, as IntPtrs don't get serialized
+            [email protected] = new []{ IntPtr.Zero, IntPtr.Zero };
 
 
             if (commonData.bodies[0] != null)
             if (commonData.bodies[0] != null)
             {
             {
@@ -369,7 +369,6 @@ namespace BansheeEngine
 
 
             public SerializableData()
             public SerializableData()
             {
             {
-                @internal.bodies = new IntPtr[2];
                 @internal.positions = new Vector3[2] { Vector3.Zero, Vector3.Zero };
                 @internal.positions = new Vector3[2] { Vector3.Zero, Vector3.Zero };
                 @internal.rotations = new Quaternion[2] { Quaternion.Identity, Quaternion.Identity };
                 @internal.rotations = new Quaternion[2] { Quaternion.Identity, Quaternion.Identity };
                 @internal.breakForce = float.MaxValue;
                 @internal.breakForce = float.MaxValue;

+ 2 - 2
Source/SBansheeEngine/Include/BsManagedComponent.h

@@ -14,8 +14,8 @@ namespace BansheeEngine
 	struct ComponentBackupData;
 	struct ComponentBackupData;
 
 
 	/**
 	/**
-	 * Component that internally wraps a managed component object that can be of user-defined type. Acts as interop interop
-	 * layer between native Component and a managed user defined component type since managed types cannot simply derive
+	 * Component that internally wraps a Mono component object that can be of user-defined type. Acts as interop
+	 * layer between native Component and a Mono user defined component type since managed types cannot simply derive
 	 * from Component to implement its functionality.
 	 * from Component to implement its functionality.
 	 */
 	 */
 	class BS_SCR_BE_EXPORT ManagedComponent : public Component
 	class BS_SCR_BE_EXPORT ManagedComponent : public Component

+ 3 - 4
Source/SBansheeEngine/Source/BsManagedSerializableObject.cpp

@@ -72,10 +72,9 @@ namespace BansheeEngine
 		if (!ScriptAssemblyManager::instance().getSerializableObjectInfo(type->mTypeNamespace, type->mTypeName, currentObjInfo))
 		if (!ScriptAssemblyManager::instance().getSerializableObjectInfo(type->mTypeNamespace, type->mTypeName, currentObjInfo))
 			return nullptr;
 			return nullptr;
 
 
-		if (type->mValueType)
-			return currentObjInfo->mMonoClass->createInstance(false);
-		else
-			return currentObjInfo->mMonoClass->createInstance();
+		// 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);
 	}
 	}
 
 
 	SPtr<ManagedSerializableObject> ManagedSerializableObject::createEmpty()
 	SPtr<ManagedSerializableObject> ManagedSerializableObject::createEmpty()