We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4204

Summary: SDL_GetRenderTarget does not return the same texture as SDL_SetRenderTarget
Product: SDL Reporter: Adam Bryant <adam.w.bryant>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: martin.veronneau
Version: 2.0.4   
Hardware: x86_64   
OS: Linux   

Description Adam Bryant 2018-06-20 06:48:54 UTC
In this sample code:

#include <iostream>
#include <SDL2/SDL.h>
#include <thread>

int main() {
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;
    SDL_CreateWindowAndRenderer(1, 1, 0, &window, &renderer);

    SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, 1, 1);
    SDL_SetRenderTarget(renderer, texture);
    SDL_Texture *renderTexture = SDL_GetRenderTarget(renderer);

    if (renderTexture != texture) {
        throw std::runtime_error("What?");
    }
    std::this_thread::sleep_for(std::chrono::seconds(1));
    return 0;
}

the exception is thrown.

Is SDL_GetRenderTarget returning a different address expected behavior?
Comment 1 Sam Lantinga 2018-06-22 17:45:29 UTC
Yes, this is expected if you're using a texture format that isn't supported by the renderer.

Try using SDL_PIXELFORMAT_ARGB8888 instead if you don't want texture conversion.
Comment 2 Adam Bryant 2018-06-22 21:17:25 UTC
(In reply to Sam Lantinga from comment #1)
> Yes, this is expected if you're using a texture format that isn't supported
> by the renderer.
> 
> Try using SDL_PIXELFORMAT_ARGB8888 instead if you don't want texture
> conversion.

Thanks, it works now.
I changed my code around to select a supported format.
Comment 3 Martin Vee 2019-06-10 18:44:46 UTC
This behaviour should be described in the wiki, as it's a bit unexpected to have a "getter" returning a different value than the "setter".

Is it possible to query a `texture->native` pointer to get it's parent `texture` pointer?