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 - SDL_SetRenderTarget unnecessarily changes target when current target is the native texture of the passed in texture
Summary: SDL_SetRenderTarget unnecessarily changes target when current target is the n...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.1
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-19 01:08 UTC by michaeljosephmaltese
Modified: 2020-12-09 14:42 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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