From ee4dee204f70b4ceb8f2db6b390b49587d50dbef Mon Sep 17 00:00:00 2001 From: John-Philip Johansson Date: Sat, 2 Sep 2023 12:25:01 +0200 Subject: [PATCH] Fix crash in UE 5.1.1 when importing new texture (#2) This fixes issue https://github.com/benui-dev/UE-BUIValidator/issues/4 by checking for pre-existing settings instead of trying to get a valid Texture Factory. Because it would likely require bigger changes if it's to work with the Interchange plugin. We check if the texture already has some settings that aren't valid and if so set the default (first) setting for each. --- .../Private/BUIValidatorModule.cpp | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Source/BUIValidator/Private/BUIValidatorModule.cpp b/Source/BUIValidator/Private/BUIValidatorModule.cpp index 70b5842..452fe42 100644 --- a/Source/BUIValidator/Private/BUIValidatorModule.cpp +++ b/Source/BUIValidator/Private/BUIValidatorModule.cpp @@ -57,29 +57,25 @@ void FBUIValidatorModule::OnObjectReimported( UFactory* ImportFactory, UObject* return; // Only apply defaults to newly-imported assets - UTextureFactory* TextureFactory = Cast( ImportFactory ); - if ( !TextureFactory->bUsingExistingSettings ) + const UBUIValidatorSettings& ValidatorSettings = *GetDefault(); + for ( const auto& Group : ValidatorSettings.ValidationGroups ) { - const UBUIValidatorSettings& ValidatorSettings = *GetDefault(); - for ( const auto& Group : ValidatorSettings.ValidationGroups ) + if ( Group.bApplyOnImport + && Group.ShouldGroupValidateAsset( InObject ) ) { - if ( Group.bApplyOnImport - && Group.ShouldGroupValidateAsset( InObject ) ) + if ( Group.ValidationRule.TextureGroups.Num() > 0 && !Group.ValidationRule.TextureGroups.Contains( Texture->LODGroup ) ) { - if ( Group.ValidationRule.TextureGroups.Num() > 0 ) - { - Texture->LODGroup = Group.ValidationRule.TextureGroups[ 0 ]; - } - - if ( Group.ValidationRule.CompressionSettings.Num() > 0 ) - { - Texture->CompressionSettings = Group.ValidationRule.CompressionSettings[ 0 ]; - } - - if ( Group.ValidationRule.MipGenSettings.Num() > 0 ) - { - Texture->MipGenSettings = Group.ValidationRule.MipGenSettings[ 0 ]; - } + Texture->LODGroup = Group.ValidationRule.TextureGroups[ 0 ]; + } + + if ( Group.ValidationRule.CompressionSettings.Num() > 0 && !Group.ValidationRule.CompressionSettings.Contains( Texture->CompressionSettings ) ) + { + Texture->CompressionSettings = Group.ValidationRule.CompressionSettings[ 0 ]; + } + + if ( Group.ValidationRule.MipGenSettings.Num() > 0 && !Group.ValidationRule.MipGenSettings.Contains( Texture->MipGenSettings )) + { + Texture->MipGenSettings = Group.ValidationRule.MipGenSettings[ 0 ]; } } }