I’ve tried to paint on a Render Target with c++. While adding RenderTarget->OnCanvasRenderTargetUpdate.AddDynamic(this, &AMyActor::UpdateThings); an error occurs: “Exception thrown: read access violation.
this was 0x500.” in line 1129 of the DelegateSignatureImpl.inl while
template< class UserClass >
void __Internal_AddDynamic( UserClass* InUserObject, typename FDelegate::template TMethodPtrResolver< UserClass >::FMethodPtr InMethodPtr, FName InFunctionName )
{
check( InUserObject != nullptr && InMethodPtr != nullptr );
// NOTE: We're not actually storing the incoming method pointer or calling it. We simply require it for type-safety reasons.
FDelegate NewDelegate;
NewDelegate.__Internal_BindDynamic( InUserObject, InMethodPtr, InFunctionName );
this->Add( NewDelegate );
}
was run.
My Function definition looks like that:
void UpdateThings(UCanvas* Canvas, int32 Width, int32 Height);
When we look at the original declaration it has the right amount of params:
/** This delegate is assignable through Blueprint and has similar functionality to the above. */
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnCanvasRenderTargetUpdate, UCanvas*, Canvas, int32, Width, int32, Height);
Did I miss something or is this an engine bug?
Full MyActor.cpp
AMyActor::AFOW_Manager()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
SetupCanvas();
}
void AFOW_Manager::UpdateThings(UCanvas* Canvas, int32 Width, int32 Height)
{
FDrawToRenderTargetContext Context;
FVector2D CanvasSize;
UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(GetWorld(), RenderTarget, Canvas, CanvasSize, Context);
Canvas->K2_DrawLine(FVector2D(0, 0), FVector2D(255, 255), 2.0f, FLinearColor::Yellow);
UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(GetWorld(), Context);
}
void AMyActor::SetupCanvas()
{
ActiveVisibilityRT->OnCanvasRenderTargetUpdate.AddDynamic(this, &AFOW_Manager::UpdateThings);
ActiveVisibilityRT->UpdateResource();
}
MyActor.h
UCLASS()
class MyName_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION()
void UpdateThings(UCanvas* Canvas, int32 Width, int32 Height);
UFUNCTION()
void SetupCanvas();
// Is set in editor with a standart 256 x 256 Canvas Render Target 2D
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UCanvasRenderTarget2D* RenderTarget;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};