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 3196

Summary: Segmentation fault when using window surface and accelerated renderer
Product: SDL Reporter: Ferdinand Vesely <erdofves>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus, philipp.wiesemann
Version: 2.0.2   
Hardware: x86_64   
OS: Linux   
Attachments: Test program
GDB backtrace leading to SDL_InvalidateMap
GDB backtrace leading to SDL_FreePalette_REAL
patch to fix a crash

Description Ferdinand Vesely 2015-12-03 18:47:43 UTC
Created attachment 2322 [details]
Test program

I get a segmentation fault (occasionally an invalid pointer error from free()) when accessing the window surface using SDL_GetWindowSurface and then creating a renderer using SDL_CreateRenderer with SDL_RENDERER_ACCELERATED on the same window. The segfault happens when SDL_DestroyWindow is called and the backtrace leads to SDL_InvalidateMap and sometimes to SDL_FreePalette_REAL.

I couldn't trigger the segfault it with SDL_RENDERER_SOFTWARE. Also if I remove the call to SDL_GetWindowSurface it works fine. Drawing using the accelerated renderer also works without a problem.

The test program is attached.
Comment 1 Ferdinand Vesely 2015-12-03 18:49:13 UTC
Created attachment 2323 [details]
GDB backtrace leading to SDL_InvalidateMap
Comment 2 Ferdinand Vesely 2015-12-03 18:50:55 UTC
Created attachment 2324 [details]
GDB backtrace leading to SDL_FreePalette_REAL
Comment 3 Philipp Wiesemann 2015-12-04 20:38:06 UTC
Created attachment 2328 [details]
patch to fix a crash

The attached patch seems to fix a crash (but maybe only by coincidence and not fixing the actual fault).
Comment 4 Ryan C. Gordon 2015-12-29 05:53:08 UTC
(In reply to Philipp Wiesemann from comment #3)
> Created attachment 2328 [details]
> patch to fix a crash
> 
> The attached patch seems to fix a crash (but maybe only by coincidence and
> not fixing the actual fault).

This looks like a good fix (whether it resolves this bug or not), so feel free to push that change if you want, Phillipp.

--ryan.
Comment 5 Philipp Wiesemann 2015-12-29 18:22:47 UTC
The first patch was applied here:
https://hg.libsdl.org/SDL/rev/08d023f75d78
Comment 6 Sam Lantinga 2016-01-02 18:20:53 UTC
Thanks!