Why is RHILockTexture2D crashed?

In c++ BeginPlay(),I just write this codes:


DynamicTexture = UTexture2D::CreateTransient(SizeX, SizeY);
FTexture2DResource Res = (FTexture2DResource)DynamicTexture ->Resource;

uint8* DestTextureData = (uint8*)RHILockTexture2D(Res->GetTexture2DRHI(), 0, RLM_WriteOnly, Stride, false);
RHIUnlockTexture2D(Res->GetTexture2DRHI(), 0, false);


when I play the game, it’s crashed! why?

If Res->GetTexture2DRHI() returns 0, RHIUnlockTexture2D will crash.