CreateCanvasRenderTarget2D - 4.6.1 -

Hi,

In BeginPlay, when I called: CreateCanvasRenderTarget2D via:
CanvasTarget = UCanvasRenderTarget2D::CreateCanvasRenderTarget2D(UCanvasRenderTarget2D::StaticClass(), SurfaceWidth, SurfaceHeight);

I have this exception:
First- exception at 0x000007FEDA618DED (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000198.
Unhandled exception at 0x000007FEDA618DED (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000198.

Did I miss something?

The code is in an Actor in a Plugin. The code is called in BeginPlay on this actor.

Thanks,

Hi,

Are you able to reproduce this?

thanks,

Hi ,

We are aware of an issue related to CreateCanvasRenderTarget2D that I think may be related to what you are seeing. Would you be able to provide some additional information?

  • Are you using the binary version of the Engine installed by the Launcher, or did you build the Engine from source code?
  • Could you provide the code you are using to set up SurfaceWidth (I’m guessing it is an int), SurfaceHeight (also an int?), and CanvasTarget (a pointer of type UCanvasRenderTarget2D?)
  • Could you provide the full callstack and project log when the crash occurs?

Thanks,

Hi,
I’m using the Binary version downloaded via the launcher
SurfaceHeight & SurfaceWidth are int32. They are initialize in the contructor of the class:
AMyClass::AMyClass(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer),SurfaceWidth(2048), SurfaceHeight(2048)
CanvasTarget is a UCanvasRenderTarget2D*

For the Log & Callstack, I will try to get them later.

Hi ,

This is the same issue that we have been working on for a while related to using CreateCanvasRenderTarget2D (UE-4570). We do not have a fix yet for the binary version of the Engine. However, if you have a version of the Engine that is built from source code, you can make a change to the following line in CanvasRenderTarget2D.cpp:

FCanvas RenderCanvas(GameThread_GetRenderTargetResource(), nullptr, FApp::GetCurrentTime() - GStartTime, FApp::GetDeltaTime(), FApp::GetCurrentTime() - GStartTime, GetWorld()->FeatureLevel);

Replace GetWorld()->FeatureLevel with GetMaxRHIFeatureLevel() and the crash should stop occurring.

Thanks for the update.
I’m not sure to understand why the fix you provided can’t be in a binary version on the Engine? Or I may have misunderstood what you said.

Could you please confirm if the fix will be in 4.7?

Thanks,

The “fix” that I mentioned above is actually a workaround. I apologize for not being clearer. It does not actually correct the issue, just masks it so that the crash no longer occurs. The reason you cannot apply the workaround to the binary version of the Engine is because it requires modifying a source code file, which you do not have access to with the binary version. If you built the Engine from source code however, the files are all available to you and you can make the change, rebuild the Engine, and you will be all set until we have a permanent fix in place.

It appears that the issue is still occurring in preview versions of 4.7, so I don’t think we will have it fixed by the time 4.7 releases. I have added the information you provided to the ticket for this issue in case it helps us develop a fix sooner.

OK I understand better now. It’s just a workaround.
Hope you will get a fix soon.

Thanks,

Hi ,

I just wanted to provide you with a quick update on this issue. A proper fix for this issue has been implemented internally, and I just ran through my tests again and the crash no longer seems to be occurring. It looks like this fix has been integrated into 4.7.