Rendertarget - Could not lock texture on DirectX 9


I am trying to render a texture which I update every frame in code.

I am creating the rendertarget like so:

SharedPtr<Texture2D> renderTarget_(new Texture2D(context));
renderTarget_->SetSize(context_->GetSubsystem<Graphics>()->GetWidth(), context_->GetSubsystem<Graphics>()->GetHeight(), Graphics::GetRGBAFormat(), TEXTURE_RENDERTARGET);

Whenever I receive updated pixels I set the texture data:

	buffer); // buffer is |width| * |height| * 4 bytes in size representing a BGRA image

Running this code with DirectX 9 renderer gives the following error at SetData()

Running the same code on Urho3D built with DirectX 11 works with no problem.
Other texture types work fine (TEXTURE_DYNAMIC for example).

What am I doing wrong here? I’d like to use DX9 if possible.

If you want to SetData() to a texture manually frequently, do not create it as a rendertarget, but as a dynamic texture. Both rendering to a texture and setting its data manually aren’t compatible.

Alright, I’ll use a dynamic texture as per your recommendation. Thanks.