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 2640

Summary: Unable to SDL_SetRenderTarget to original surface for software renderer without a window
Product: SDL Reporter: Damian Kaczmarek <rush>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: Test showing the reported problem
Fix the issue by explicitly setting renderer's window to backing surface

Description Damian Kaczmarek 2014-07-12 23:45:17 UTC
Created attachment 1748 [details]
Test showing the reported problem

Basically this bug is probably not a common use case. My goal is to allow rendering totally without a window, for example to a screenshot and I need to rely on SDL_SetRenderTarget to properly work for a purely software renderer created by SDL_CreateSoftwareRenderer.

Some facts:
0) Possibly does not work for SDL 2.0.0
1) WORKS properly for SDL 2.0.3
2) Does not work for latest HG
Could be bisected probably, can HG do this?

I attach a test case which properly renders on SDL 2.0.3 (it has rendering from bug #1743) but the window is totally black for latest SDL from hg.

g++ sdl2_software_set_render_target_bug.cpp -lSDL2 && ./a.out

Expected: Green screen with moving rectangle
Comment 1 Damian Kaczmarek 2014-07-13 09:22:20 UTC
Created attachment 1749 [details]
Fix the issue by explicitly setting renderer's window to backing surface

Actually please scratch the "WORKS properly for SDL 2.0.3" part. I actually have fixed this problem in SDL sources before but couldn't connect the dots due to the other bug also occurring at the same time. I attach a patch which fixes the problem. Please review if doesn't break anything else. In my opinion it makes sense as "window" is assumed for all renderers so for the software renderer setting window to its backing surface makes only sense.
Comment 2 Sam Lantinga 2014-07-13 16:05:39 UTC
Your patch looks good, thanks!
https://hg.libsdl.org/SDL/rev/f061a86fbb08