Windows & displaysSDL 3.2

SDL_DestroyWindow

Closes a window and frees it.

Signature

void SDL_DestroyWindow(SDL_Window *window);

How it works

Destroy what draws into the window first: its renderer (SDL_DestroyRenderer), its OpenGL context or its Vulkan surface. Then the window, then SDL_Quit at the very end.

In C++ a std::unique_ptr with a deleter that calls this function makes the order automatic.

Parameters

windowSDL_Window *

The window to destroy.

Example

example.cpp
1struct SdlDeleter {
2    void operator()(SDL_Window* w) const noexcept { SDL_DestroyWindow(w); }
3};
4std::unique_ptr<SDL_Window, SdlDeleter> window{SDL_CreateWindow("App", 800, 600, 0)};
Official SDL wiki