Pārlūkot izejas kodu

Fixing issues when attempting to serialize and deserialize null objects

BearishSun 10 gadi atpakaļ
vecāks
revīzija
8c7b5abb5a

+ 7 - 4
BansheeEditor/Source/BsBuildManager.cpp

@@ -104,10 +104,13 @@ namespace BansheeEngine
 
 	void BuildManager::load(const Path& inFile)
 	{
-		if (!FileSystem::exists(inFile))
-			return;
+		if (FileSystem::exists(inFile))
+		{
+			FileDecoder fd(inFile);
+			mBuildData = std::static_pointer_cast<BuildData>(fd.decode());
+		}
 
-		FileDecoder fd(inFile);
-		mBuildData = std::static_pointer_cast<BuildData>(fd.decode());
+		if (mBuildData == nullptr)
+			mBuildData = bs_shared_ptr_new<BuildData>();
 	}
 }

+ 3 - 0
BansheeUtility/Source/BsBinarySerializer.cpp

@@ -121,6 +121,9 @@ namespace BansheeEngine
 
 	std::shared_ptr<IReflectable> BinarySerializer::decode(UINT8* data, UINT32 dataLength)
 	{
+		if (dataLength == 0)
+			return nullptr;
+
 		SPtr<SerializedObject> intermediateObject = _decodeIntermediate(data, dataLength);
 		if (intermediateObject == nullptr)
 			return nullptr;

+ 3 - 0
BansheeUtility/Source/BsFileSerializer.cpp

@@ -37,6 +37,9 @@ namespace BansheeEngine
 
 	void FileEncoder::encode(IReflectable* object)
 	{
+		if (object == nullptr)
+			return;
+
 		UINT64 curPos = (UINT64)mOutputStream.tellp();
 		mOutputStream.seekp(sizeof(UINT32), std::ios_base::cur);