Skip to content

Commit 55073aa

Browse files
committed
Examples; SDL: added missing return values checks from SDL_CreateWindow() calls. (#7147)
1 parent 8764a1b commit 55073aa

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

examples/example_sdl2_directx11/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ int main(int, char**)
4747
// Setup window
4848
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
4949
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+DirectX11 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
50+
if (window == nullptr)
51+
{
52+
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
53+
return -1;
54+
}
55+
5056
SDL_SysWMinfo wmInfo;
5157
SDL_VERSION(&wmInfo.version);
5258
SDL_GetWindowWMInfo(window, &wmInfo);

examples/example_sdl2_opengl2/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ int main(int, char**)
4141
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
4242
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
4343
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
44+
if (window == nullptr)
45+
{
46+
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
47+
return -1;
48+
}
49+
4450
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
4551
SDL_GL_MakeCurrent(window, gl_context);
4652
SDL_GL_SetSwapInterval(1); // Enable vsync

examples/example_sdl2_opengl3/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ int main(int, char**)
6868
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
6969
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
7070
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
71+
if (window == nullptr)
72+
{
73+
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
74+
return -1;
75+
}
76+
7177
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
7278
SDL_GL_MakeCurrent(window, gl_context);
7379
SDL_GL_SetSwapInterval(1); // Enable vsync

examples/example_sdl2_sdlrenderer2/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ int main(int, char**)
3838
// Create window with SDL_Renderer graphics context
3939
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
4040
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+SDL_Renderer example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
41+
if (window == nullptr)
42+
{
43+
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
44+
return -1;
45+
}
4146
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
4247
if (renderer == nullptr)
4348
{

examples/example_sdl2_vulkan/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ int main(int, char**)
385385
// Create window with Vulkan graphics context
386386
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
387387
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
388+
if (window == nullptr)
389+
{
390+
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
391+
return -1;
392+
}
388393

389394
ImVector<const char*> extensions;
390395
uint32_t extensions_count = 0;

0 commit comments

Comments
 (0)