Download

[Slate] UTexture2D in Details Panel Customization crashes editor on compile

I have a UObject derived class called USomeTestObject, in a separated editor module i have a class that customizes the details panel of said object blueprint instances, with a texture.

The texture is drawn correctly as you can see from the image, but as soon as i hit compile on the blueprint, the editor crashes.
The behaviour is not deterministic, sometimes the editor doesn’t crash but the texture isn’t drawn anymore, hitting compile multiple times almost ensures a crash.

fb3f1863b1c6593fc221bf95084a33b5923aef0e.png
https://forums.unrealengine.com/core/image/gif;base64

The details customization class

[SPOILER]



class FSomeObjectDetails : public IDetailCustomization
{
public:

   FSomeObjectDetails();

    /* Makes a new instance of this detail layout class for a specific detail view requesting it */
   static TSharedRef<IDetailCustomization> MakeInstance();

   /*
   * IDetailCustomization interface implementation
   */
   virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;

protected:
   class UTexture2D* SomeTexture;
   struct FSlateBrush Brush;

   int32 TextureSizeX;
   int32 TextureSizeY;
};





FSomeObjectDetails::FSomeObjectDetails()
{
   TextureSizeX = 256;
   TextureSizeY = 256;

   SomeTexture = UTexture2D::CreateTransient(TextureSizeX, TextureSizeY, EPixelFormat::PF_G8);

   uint32 Count = TextureSizeX * TextureSizeY;
   TArray<uint8> Pixels;
   Pixels.AddZeroed(Count);

   for(uint32 i = 0; i < Count; i ++)
   {
      Pixels* = 255.0f * ((float)i / Count);
   }

   SomeTexture->Source.Init(TextureSizeX, TextureSizeY, 1, 1, ETextureSourceFormat::TSF_G8, Pixels.GetData());
   SomeTexture->UpdateResource();
   SomeTexture->PostEditChange();
}

TSharedRef<IDetailCustomization> FSomeObjectDetails::MakeInstance()
{
   return MakeShareable(new FSomeObjectDetails);
}

void FSomeObjectDetails::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{

   TArray<TWeakObjectPtr<UObject>> SelectedObjects = DetailBuilder.GetSelectedObjects();
   if (SelectedObjects.Num() != 1)
   {
      return;
   }

   TWeakObjectPtr<UObject> SelectedObject = SelectedObjects[0];
   if (!SelectedObject.IsValid())
   {
      return;
   }

   const TWeakObjectPtr<USomeTestObject> CurrentObject = Cast<USomeTestObject>(SelectedObject.Get());

   if(!CurrentObject.Get())
   {
      return;
   }

   // Edit a category. If it doesn't exist it creates a new one
   IDetailCategoryBuilder& CustomCategory = DetailBuilder.EditCategory("Some Texture");

   Brush.SetResourceObject( SomeTexture );
   Brush.ImageSize.X = TextureSizeX;
   Brush.ImageSize.Y = TextureSizeY;
   Brush.DrawAs = ESlateBrushDrawType::Image;

   //Adding a custom row
   CustomCategory.AddCustomRow(FText::FromString("Texture Preview"))
   .ValueContent()
   .MaxDesiredWidth(TextureSizeX)
   .VAlign(VAlign_Center) // set vertical alignment to center
   
   SNew(SImage)
   .Image(&Brush)
   ];
}


[/SPOILER]

The class being customized

[SPOILER]


UCLASS(Blueprintable)
class TESTPROJECT_API USomeTestObject : public UObject
{
GENERATED_BODY()

public:
   void SomeMethod();

   UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
   float SomeScalar;
};

[/SPOILER]

The crash log:

[SPOILER]


Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000008

UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_PropertyEditor
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_SlateCore
UE4Editor_Slate
UE4Editor_Slate
UE4Editor_Slate
UE4Editor_Slate
UE4Editor_Slate
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

[/SPOILER]