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 4559 - SDL_SetVideoMode will fail when called twice if returned surface is freed with SDL_FreeSurface
Summary: SDL_SetVideoMode will fail when called twice if returned surface is freed wit...
Status: RESOLVED FIXED
Alias: None
Product: sdl12-compat
Classification: Unclassified
Component: everything (show other bugs)
Version: unspecified
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-21 11:50 UTC by Dario
Modified: 2019-03-22 13:44 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dario 2019-03-21 11:50:31 UTC
SDL_SetVideoMode(int,int,int,Uint32) returns a VideoSurface12 (SDL12_Surface *).
An application hold this pointer and call to SDL_FreeSurface(SDL12_Surface *).

A second call to SDL_SetVideo_Mode results in a segmentation fault because VideoSurface12 has been invalidated, is not NULL and will be accessed.

I can bypass this issue by adding a conditional on the SDL_FreeSurface that tests the SDL12_Surface pointer for equality against the VideoSurface12.

I encountered this problem while trying a game development engine called BennuGD (https://bitbucket.org/dacucar/bennugd/src/master/) which runs on SDL 1.2.

After doing my small hack, I was able to run a relatively complex game without much trouble.

If you need additional information, let me know.
Comment 1 Ryan C. Gordon 2019-03-21 15:15:19 UTC
Ah, interesting...you aren't supposed to call SDL_FreeSurface() on the return value from SDL_SetVideoMode(), but I see that SDL 1.2 checks for this case and returns immediately if trying to free the screen surface.

I'll fix that.

--ryan.
Comment 2 Dario 2019-03-21 16:09:13 UTC
Interesting, that is exactly what I did to solve it.

You are right in any case, I checked the SDL 1.2 documentation and it says the surface should not be freed. 

So I guess I will have to report that too to the other project :).

I can also advance that, when adding the VideoSurface12 check and returning on the SDL_FreeSurface I encountered that when switching from FullScreen to Windowed mode, the game was not correctly scaled: it is as if the game stayed "large" but the area was clipt to the size of the window screen.
Comment 3 Dario 2019-03-21 16:47:52 UTC
Regarding the later, I will investigate further and report when I know more.
Comment 4 Ryan C. Gordon 2019-03-22 13:44:44 UTC
> Regarding the later, I will investigate further and report when I know more.

Please do, and open a separate bug for it so we don't forget to fix it!  :)

As for this bug: fixed in https://hg.libsdl.org/sdl12-compat/rev/f4f3bf9e36e1, thanks!

--ryan.