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 5291

Summary: SDL_SetRenderTarget unnecessarily changes target when current target is the native texture of the passed in texture
Product: SDL Reporter: michaeljosephmaltese
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.1   
Hardware: All   
OS: All   

Description michaeljosephmaltese 2020-09-19 01:08:46 UTC
Suggested patch:

```diff
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1879,12 +1879,6 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
     if (!SDL_RenderTargetSupported(renderer)) {
         return SDL_Unsupported();
     }
-    if (texture == renderer->target) {
-        /* Nothing to do! */
-        return 0;
-    }
-
-    FlushRenderCommands(renderer);  /* time to send everything to the GPU! */
 
     /* texture == NULL is valid and means reset the target to the window */
     if (texture) {
@@ -1900,6 +1894,13 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
             texture = texture->native;
         }
     }
+
+    if (texture == renderer->target) {
+        /* Nothing to do! */
+        return 0;
+    }
+
+    FlushRenderCommands(renderer);  /* time to send everything to the GPU! */
 
     SDL_LockMutex(renderer->target_mutex);
 
```
Comment 1 Sam Lantinga 2020-12-09 14:42:53 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/beac59a42e37