# Window size not changing when leaving fullscreen

**URL:** <https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494>\
**Category:** SDL Development\
**Created:** [October 5, 2026, 8:49pm UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494 "2026-10-05T20:49:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![javinson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/javinson/32/5897_2.png) [@javinson](https://discourse.libsdl.org/u/javinson)\
**Post date:** [October 5, 2026, 8:49pm UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/1 "2026-10-05T20:49:37Z")

</div>

My program initially starts in windowed at an arbitrary resolution of 1920 x 1080, and I want it to swap between windowed and fullscreen with a button press. When it goes into fullscreen, it behaves as expected, but when leaving fullscreen I get very strange behavior that changes depending on if I am running the debugger or not.

While running the program on its own, the window will leave fullscreen but remain at my monitor’s size of 2560 x 1600. However, if the program is running in the debugger and I am stepping through each line individually, it behaves as expected.

This is the code for initializing the `SDL_Window` used for the program display.

```auto
	// Display init //
	const char8 windowTitle[] = "Game Window";
	const uint32 displayDefaultW_px = 1920;
	const uint32 displayDefaultH_px = 1080;
	state->displayScale = 1080.0;
	state->displayW_px = displayDefaultW_px;
	state->displayH_px = displayDefaultH_px;
	/* Initialize internal struct that will hold the first display frame data */

	SDL_Window* window = SDL_CreateWindow(windowTitle, state->displayW_px, state->displayH_px, SDL_WINDOW_VULKAN);
	SDL_SetWindowTitle(window, windowTitle);
	SDL_Surface* surface = SDL_GetWindowSurface(window);
	surface->format = SDL_PIXELFORMAT_RGB24;

```

This is the code in the main loop to handle changing fullscreen status. It runs after collecting all user input from SDL and before any other functions like updating program logic and sending video/audio data to SDL. The `if` block handles going from windowed to fullscreen, and works correctly; the window becomes fullscreen and the display in the window fills up the newly acquired space. The `else if` block handles the reverse case of going back to windowed, and is where the problems happen.

```auto
if (input.fullscreen == pressed && !state->isFullscreen) {
	SDL_SetWindowFullscreen(window, true);
	SDL_SyncWindow(window);
	surface = SDL_GetWindowSurface(window);
	state->displayW_px = surface->w;
	state->displayH_px = surface->h;
	state->isFullscreen = true;
}
else if (input.fullscreen == pressed && state->isFullscreen) {
	SDL_SetWindowFullscreen(window, false);
	SDL_SyncWindow(window);
	SDL_SetWindowSize(window, displayDefaultW_px, displayDefaultH_px);
	SDL_SyncWindow(window);
	surface = SDL_GetWindowSurface(window);
	state->displayW_px = surface->w;
	state->displayH_px = surface->h;
	state->isFullscreen = false;
}

```

I’m not sure why this doesn’t work as expected and even more confused as to why it works just fine when stepping through the debugger. My first thought was that there was some sort of timing/parallelism issue, but I figured that `SDL_SyncWindow` should have prevented those.

---

<div class="post-metadata">

**Author:** ![Peter87](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/f07891/32.png) [@Peter87](https://discourse.libsdl.org/u/Peter87)\
**Post date:** [October 5, 2026, 9:06pm UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/2 "2026-10-05T21:06:51Z")

</div>

Have you checked if `SDL_SyncWindow` returns true?

---

<div class="post-metadata">

**Author:** ![Brian\_Raiter](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@Brian\_Raiter](https://discourse.libsdl.org/u/Brian_Raiter)\
**Post date:** [October 5, 2026, 10:01pm UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/3 "2026-10-05T22:01:04Z")

</div>

> [@javinson](#):
>
> ```rust
> 
> ```
> 
> I’m not sure why this doesn’t work as expected and even more confused as to why it works just fine when stepping through the debugger.

In my experience this frequently indicates the presence an uninitialized variable. A debugger will change what random value uninitialized memory will contain, sometimes in ways that are consistent from run to run, whereas outside the debugger it will be unpredictable.

Your sample code doesn’t show where `input.fullscreen` or `state->isFullscreen` gets set, for example, so those might be a good place to start looking.

---

<div class="post-metadata">

**Author:** ![Sward](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sward/32/5719_2.png) [@Sward](https://discourse.libsdl.org/u/Sward)\
**Post date:** [October 7, 2026, 5:09pm UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/4 "2026-10-07T17:09:18Z")

</div>

Another common issue: try a search of your code for any other place where your code might be setting a window size.

The SDL\_EVENT\_WINDOW\_RESIZED, and SDL\_EVENT\_WINDOW\_LEAVE\_FULLSCREEN event handlers are likely spots, but just do a general search for the SDL\_SetWindowSize function in all of your project files.

---

<div class="post-metadata">

**Author:** ![javinson](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/javinson/32/5897_2.png) [@javinson](https://discourse.libsdl.org/u/javinson)\
**Post date:** [October 7, 2026, 8:19pm UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/5 "2026-10-07T20:19:09Z")

</div>

Yes. I should have mentioned it in the post, but I also tried asserting the `SDL_SyncWindow` calls and it did not stop the program.

---

<div class="post-metadata">

**Author:** ![Peter87](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/f07891/32.png) [@Peter87](https://discourse.libsdl.org/u/Peter87)\
**Post date:** [October 8, 2026, 10:11am UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/6 "2026-10-08T10:11:24Z")

</div>

You might want to try moving the code that follows the `SDL_SetWindowFullscreen` call and instead run it when receiving a `SDL_EVENT_WINDOW_LEAVE_FULLSCREEN` event. You could also move the `SDL_GetWindowSurface` code and run it in response to a `SDL_EVENT_WINDOW_RESIZED` event. This way you can get rid of all the `SDL_SyncWindow` calls. Maybe this works better, I don’t know…

```auto
// in response to the key press...
SDL_SetWindowFullscreen(window, false);

// when receiving a SDL_EVENT_WINDOW_LEAVE_FULLSCREEN event...
SDL_SetWindowSize(window, displayDefaultW_px, displayDefaultH_px);
state->isFullscreen = false;

// when receiving a SDL_EVENT_WINDOW_RESIZED event...
SDL_Surface* surface = SDL_GetWindowSurface(window);
state->displayW_px = surface->w;
state->displayH_px = surface->h;

```

* * *

Normally I don’t think it should be necessary to call `SDL_SetWindowSize` when leaving fullscreen mode because I would expect `SDL_SetWindowFullscreen(window, false);` to restore the previous size that was used before entering fullscreen mode (or that you specified when calling `SDL_CreateWindow` if windowed mode has never been used). If this doesn’t happen when leaving out the `SDL_SetWindowSize` call then you might want to consider [reporting it as a bug](https://github.com/libsdl-org/SDL/issues).

---

<div class="post-metadata">

**Author:** ![Peter87](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/f07891/32.png) [@Peter87](https://discourse.libsdl.org/u/Peter87)\
**Post date:** [October 8, 2026, 10:54am UTC](https://discourse.libsdl.org/t/window-size-not-changing-when-leaving-fullscreen/69494/7 "2026-10-08T10:54:29Z")

</div>

And another thing… The docs for [SDL\_GetWindowSurface](https://wiki.libsdl.org/SDL3/SDL_GetWindowSurface) says:

> You may not combine this with 3D or the rendering API on this window.

Since you use `SDL_WINDOW_VULKAN` I thought you might be using the render, gpu or vulkan api for rendering. Maybe that could cause some problems. Just a thought…

Anyway, you can’t set the format of a surface just like that:

```auto
surface->format = SDL_PIXELFORMAT_RGB24;

```

_Note how the `format` comment in the [SDL\_Surface](https://wiki.libsdl.org/SDL3/SDL_Surface) docs says “read-only”._
