From f4d5a75574098ed9e67f6badf29ddf9e95de9d3e Mon Sep 17 00:00:00 2001 From: santorac <55155825+santorac@users.noreply.github.com> Date: Thu, 21 Oct 2021 12:13:45 -0700 Subject: [PATCH] Fixed an issue where the wrong version number was being reported in a warning message. It showed the latest version instead of the original version number. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com> --- .../Code/Source/RPI.Edit/Material/MaterialSourceData.cpp | 2 +- .../RPI/Code/Source/RPI.Reflect/Material/MaterialAsset.cpp | 6 ++++-- Gems/Atom/RPI/Code/Tests/Material/MaterialAssetTests.cpp | 2 ++ .../RPI/Code/Tests/Material/MaterialSourceDataTests.cpp | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialSourceData.cpp b/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialSourceData.cpp index 9d44963942..5aed6b2993 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialSourceData.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Edit/Material/MaterialSourceData.cpp @@ -119,7 +119,7 @@ namespace AZ if (changesWereApplied) { AZ_Warning("MaterialSourceData", false, - "This material is based on version %u of '%s', but the material type is now at version %u. " + "This material is based on version '%u' of '%s', but the material type is now at version '%u'. " "Automatic updates are available. Consider updating the .material source file.", m_materialTypeVersion, m_materialType.c_str(), materialTypeSourceData.m_version); } diff --git a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialAsset.cpp b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialAsset.cpp index 2b7c1c58c7..e9d8a42641 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialAsset.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Reflect/Material/MaterialAsset.cpp @@ -208,6 +208,8 @@ namespace AZ return; } + const uint32_t originalVersion = m_materialTypeVersion; + bool changesWereApplied = false; for (const MaterialVersionUpdate& versionUpdate : m_materialTypeAsset->GetMaterialVersionUpdateList()) @@ -225,9 +227,9 @@ namespace AZ if (changesWereApplied) { AZ_Warning("MaterialAsset", false, - "This material is based on version %u of '%s', but the material type is now at version %u. " + "This material is based on version '%u' of %s, but the material type is now at version '%u'. " "Automatic updates are available. Consider updating the .material source file.", - m_materialTypeVersion, m_materialTypeAsset.ToString().c_str(), m_materialTypeAsset->GetVersion()); + originalVersion, m_materialTypeAsset.ToString().c_str(), m_materialTypeAsset->GetVersion()); } m_materialTypeVersion = m_materialTypeAsset->GetVersion(); diff --git a/Gems/Atom/RPI/Code/Tests/Material/MaterialAssetTests.cpp b/Gems/Atom/RPI/Code/Tests/Material/MaterialAssetTests.cpp index cf8b55d581..58a852f176 100644 --- a/Gems/Atom/RPI/Code/Tests/Material/MaterialAssetTests.cpp +++ b/Gems/Atom/RPI/Code/Tests/Material/MaterialAssetTests.cpp @@ -264,6 +264,8 @@ namespace UnitTest // This can find errors and warnings, we are looking for a warning when the version update is applied ErrorMessageFinder warningFinder; warningFinder.AddExpectedErrorMessage("Automatic updates are available. Consider updating the .material source file"); + warningFinder.AddExpectedErrorMessage("This material is based on version '1'"); + warningFinder.AddExpectedErrorMessage("material type is now at version '2'"); // Even though this material was created using the old version of the material type, it's property values should get automatically // updated to align with the new property layout in the latest MaterialTypeAsset. diff --git a/Gems/Atom/RPI/Code/Tests/Material/MaterialSourceDataTests.cpp b/Gems/Atom/RPI/Code/Tests/Material/MaterialSourceDataTests.cpp index 6a6947e7c7..acce52ae8e 100644 --- a/Gems/Atom/RPI/Code/Tests/Material/MaterialSourceDataTests.cpp +++ b/Gems/Atom/RPI/Code/Tests/Material/MaterialSourceDataTests.cpp @@ -728,6 +728,8 @@ namespace UnitTest // Then we force the material data to update to the latest material type version specification ErrorMessageFinder warningFinder; // Note this finds errors and warnings, and we're looking for a warning. warningFinder.AddExpectedErrorMessage("Automatic updates are available. Consider updating the .material source file"); + warningFinder.AddExpectedErrorMessage("This material is based on version '1'"); + warningFinder.AddExpectedErrorMessage("material type is now at version '10'"); material.ApplyVersionUpdates(); warningFinder.CheckExpectedErrorsFound();