Skip to content

Commit

Permalink
Fix crash in UE 5.1.1 when importing new texture (#2)
Browse files Browse the repository at this point in the history
This fixes issue benui-dev#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.
  • Loading branch information
seriema authored Sep 2, 2023
1 parent 8392c59 commit ee4dee2
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions Source/BUIValidator/Private/BUIValidatorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,25 @@ void FBUIValidatorModule::OnObjectReimported( UFactory* ImportFactory, UObject*
return;

// Only apply defaults to newly-imported assets
UTextureFactory* TextureFactory = Cast<UTextureFactory>( ImportFactory );
if ( !TextureFactory->bUsingExistingSettings )
const UBUIValidatorSettings& ValidatorSettings = *GetDefault<UBUIValidatorSettings>();
for ( const auto& Group : ValidatorSettings.ValidationGroups )
{
const UBUIValidatorSettings& ValidatorSettings = *GetDefault<UBUIValidatorSettings>();
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 ];
}
}
}
Expand Down

0 comments on commit ee4dee2

Please sign in to comment.