From afcbe4e02b64b5a4820f99a01d843a6f8a27f570 Mon Sep 17 00:00:00 2001 From: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com> Date: Tue, 4 May 2021 13:51:08 -0700 Subject: [PATCH] Small updates based on PR feedback. --- .../AzCore/AzCore/Serialization/Json/JsonSerialization.h | 3 +++ .../Tests/Serialization/Json/BaseJsonSerializerTests.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h b/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h index b92eae7d6b..cf73d8dc56 100644 --- a/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h +++ b/Code/Framework/AzCore/AzCore/Serialization/Json/JsonSerialization.h @@ -49,6 +49,9 @@ namespace AZ //! Note on pointers: The Json Serialization assumes that are always constructed, so a default JSON value of "{}" is interpret as //! creating a new default instance even if the default value is a null pointer. A JSON Null needs to be explicitly stored in //! the JSON Document in order to default or explicitly set a pointer to null. + //! Note on pointer memory: Objects created/destroyed by the Json Serialization for pointers require that the AZ_CLASS_ALLOCATOR is + //! declared and the object is created using aznew or memory is allocated using azmalloc. Without these the application may + //! crash if the Json Serialization tries to create or destroy an object pointed to by a pointer. class JsonSerialization final { public: diff --git a/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp b/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp index 62622ef7ab..08de21b54f 100644 --- a/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp +++ b/Code/Framework/AzCore/Tests/Serialization/Json/BaseJsonSerializerTests.cpp @@ -140,7 +140,7 @@ namespace JsonSerializationTests ASSERT_NE(nullptr, ptrValue); EXPECT_EQ(42, *ptrValue); - azfree(ptrValue, AZ::SystemAllocator, sizeof(int), AZStd::alignment_of::value); + azfree(ptrValue, AZ::SystemAllocator, sizeof(int), alignof(int)); } TEST_F(BaseJsonSerializerTests, ContinueLoading_DefaultToNullPointer_ValueLoadedCorrectly) @@ -155,7 +155,7 @@ namespace JsonSerializationTests EXPECT_EQ(Processing::Completed, result.GetProcessing()); ASSERT_NE(nullptr, ptrValue); - azfree(ptrValue, AZ::SystemAllocator, sizeof(int), AZStd::alignment_of::value); + azfree(ptrValue, AZ::SystemAllocator, sizeof(int), alignof(int)); } TEST_F(BaseJsonSerializerTests, ContinueLoading_NullDeletesObject_ValueLoadedCorrectly) @@ -163,7 +163,7 @@ namespace JsonSerializationTests using namespace AZ::JsonSerializationResult; rapidjson::Value json(rapidjson::kNullType); - int* ptrValue = reinterpret_cast(azmalloc(sizeof(int), AZStd::alignment_of::value, AZ::SystemAllocator)); + int* ptrValue = reinterpret_cast(azmalloc(sizeof(int), alignof(int), AZ::SystemAllocator)); ResultCode result = ContinueLoading(&ptrValue, azrtti_typeid(), json, *m_jsonDeserializationContext, Flags::ResolvePointer);