I am trying to learn SDL and I have an application where I want to draw to a textureout of the paint cycle of the application and then I only have to copy the texture to the screen during the refresh cycle. I have two methods to my class that do this:
Tester::CreateTexture(SDL_Renderer* pRenderer, XPoint<int>* pResolution)
{
    mResolution.x = pResolution->x;
    mResolution.y = pResolution->y;
    std::cout << "Renderer: " << pRenderer << std::endl;
    SDL_ClearError();
    mpTexture = SDL_CreateTexture(pRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, mResolution.x, mResolution.y);
    std::cout << "BeamformImage: " << mpTexture << " : " << mResolution.x << ", " << mResolution.y << std::endl;
    int foo = SDL_SetRenderTarget(pRenderer, mpTexture);
    std::cout << "Set Renderer: Cn: " << foo << " : " << SDL_GetError() << std::endl;
    int bar = SDL_SetRenderTarget(pRenderer, NULL);
    std::cout << "Set Renderer: Tn: " << bar << " : " << SDL_GetError() << std::endl;
}
This method creates the texture and saves it as an instance variable. I added code to set the target of the renderer to see if it works and there is no error and both calls return 0 as expected.
Then I have a method that wants to write to the texture:
void Tester::WriteTexture(SDL_Renderer* pRenderer)
{
    SDL_ClearError();
    std::cout << "Renderer: " << pRenderer << " : " << mpTexture << std::endl;
    int foo = SDL_SetRenderTarget(pRenderer, mpTexture);
    std::cout << "Render Target: " << foo << " : " << SDL_GetError() << std::endl;
    // Code to write to the renderer
}
The renderer is always the same in both methods and the texture is the same.
When Write Texture is called foo is -1 and the error is Invalid texture.
Is there a way to find out what the issue with the texture is? Is the problem that I have somehow trashed the renderer between the two calls?
A added this at the bottom of each of the methods to see if somehow the renderer changed and wouldn't allow rendering to textures
SDL_RendererInfo info;
SDL_GetRendererInfo(pRenderer, &info);
if (info.flags && SDL_RENDERER_TARGETTEXTURE > 0)
    std::cout << "*Can Target Texture: " << std::endl;
else
    std::cout << "*Can't Target Texture: " << std::endl;
In both places rendering to textures seems to be allowed.