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 4740

Summary: SDL_UpdateWindowSurface() failed for resized window
Product: SDL Reporter: Koichi Yoshida <koichi.yoshida>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: amaranth72
Version: 2.0.9   
Hardware: x86_64   
OS: Linux   
Attachments: reproducible code
reproducible code ver2

Description Koichi Yoshida 2019-07-26 12:31:39 UTC
Created attachment 3901 [details]
reproducible code

I found a problem that SDL_UpdateWindowSurface() failed for a window resized by SDL_SetWindowSize().
The window is created as "not full screen" and resizable. 

I have attached a reproducible code for the problem.

Tested environment:
	debian 10.0.0 amd64
	sdl2.0.9+dfsg1-1

How to reproduce the problem:
	gcc sdl2_UpdateWindowSurface_failed.c -lSDL2 && ./a.out
	In case of SDL_UpdateWindowSurface() failed, you can see an error message as follows.
	> SDL_UpdateWindowSurface failed: Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface
Comment 1 Alex Szpakowski 2019-07-27 17:19:57 UTC
*** Bug 4741 has been marked as a duplicate of this bug. ***
Comment 2 Alex Szpakowski 2019-07-27 17:22:39 UTC
The documentation says you need to call SDL_GetWindowSurface to obtain a valid surface, whenever the window is resized.
Comment 3 Koichi Yoshida 2019-07-28 02:24:44 UTC
Thank you for replying to my post.
I am sorry for duplicating.

After the window has been resized, the reproducible code calls SDL_GetWindowSurface ().
This is correct?
Comment 4 Koichi Yoshida 2019-07-28 05:07:14 UTC
Created attachment 3906 [details]
reproducible code ver2

TEST_CASE 0 shows the SIGSEGV case.
TEST_CASE 1~3 shows how to avoid the SIGSEGV.
Comment 5 Koichi Yoshida 2019-07-28 05:27:48 UTC
I found the problem looks like caused by timing.
If it sleeps 1 seconds after SDL_SetWindowSize(), it works correctly (TEST_CASE 2&3).
Also, if it cancels drawing when the surface width and height has not been changed correctly, it works correctly (TEST_CASE 1&3).