Skip to content

Commit cee40f8

Browse files
committed
Examples: made examples's main.cpp consistent with returning 1 on error.
1 parent 940627d commit cee40f8

File tree

13 files changed

+34
-33
lines changed

13 files changed

+34
-33
lines changed

docs/CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Other Changes:
6767
- Examples: SDL2+DirectX11: Try WARP software driver if hardware driver is
6868
not available. (#5924, #5562)
6969
- Examples: SDL3+DirectX11: Added SDL3+DirectX11 example. (#8956, #8957) [@tomaz82]
70+
- Examples: made examples's main.cpp consistent with returning 1 on error.
7071

7172

7273
-----------------------------------------------------------------------

examples/example_sdl2_directx11/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(int, char**)
3939
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
4040
{
4141
printf("Error: %s\n", SDL_GetError());
42-
return -1;
42+
return 1;
4343
}
4444

4545
// From 2.0.18: Enable native IME.
@@ -54,7 +54,7 @@ int main(int, char**)
5454
if (window == nullptr)
5555
{
5656
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
57-
return -1;
57+
return 1;
5858
}
5959

6060
SDL_SysWMinfo wmInfo;

examples/example_sdl2_metal/main.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int main(int, char**)
5151
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
5252
{
5353
printf("Error: %s\n", SDL_GetError());
54-
return -1;
54+
return 1;
5555
}
5656

5757
// Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.

examples/example_sdl2_opengl2/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(int, char**)
3131
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
3232
{
3333
printf("Error: %s\n", SDL_GetError());
34-
return -1;
34+
return 1;
3535
}
3636

3737
// From 2.0.18: Enable native IME.
@@ -51,7 +51,7 @@ int main(int, char**)
5151
if (window == nullptr)
5252
{
5353
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
54-
return -1;
54+
return 1;
5555
}
5656

5757
SDL_GLContext gl_context = SDL_GL_CreateContext(window);

examples/example_sdl2_opengl3/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main(int, char**)
3636
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
3737
{
3838
printf("Error: %s\n", SDL_GetError());
39-
return -1;
39+
return 1;
4040
}
4141

4242
// Decide GL+GLSL versions
@@ -85,14 +85,14 @@ int main(int, char**)
8585
if (window == nullptr)
8686
{
8787
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
88-
return -1;
88+
return 1;
8989
}
9090

9191
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
9292
if (gl_context == nullptr)
9393
{
9494
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
95-
return -1;
95+
return 1;
9696
}
9797

9898
SDL_GL_MakeCurrent(window, gl_context);

examples/example_sdl2_sdlrenderer2/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int, char**)
3333
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
3434
{
3535
printf("Error: %s\n", SDL_GetError());
36-
return -1;
36+
return 1;
3737
}
3838

3939
// From 2.0.18: Enable native IME.
@@ -48,13 +48,13 @@ int main(int, char**)
4848
if (window == nullptr)
4949
{
5050
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
51-
return -1;
51+
return 1;
5252
}
5353
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
5454
if (renderer == nullptr)
5555
{
5656
SDL_Log("Error creating SDL_Renderer!");
57-
return -1;
57+
return 1;
5858
}
5959
//SDL_RendererInfo info;
6060
//SDL_GetRendererInfo(renderer, &info);

examples/example_sdl2_vulkan/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ int main(int, char**)
349349
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
350350
{
351351
printf("Error: %s\n", SDL_GetError());
352-
return -1;
352+
return 1;
353353
}
354354

355355
// From 2.0.18: Enable native IME.
@@ -364,7 +364,7 @@ int main(int, char**)
364364
if (window == nullptr)
365365
{
366366
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
367-
return -1;
367+
return 1;
368368
}
369369

370370
ImVector<const char*> extensions;

examples/example_sdl3_directx11/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int, char**)
3434
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
3535
{
3636
printf("Error: SDL_Init(): %s\n", SDL_GetError());
37-
return -1;
37+
return 1;
3838
}
3939

4040
// Setup window
@@ -44,7 +44,7 @@ int main(int, char**)
4444
if (window == nullptr)
4545
{
4646
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
47-
return -1;
47+
return 1;
4848
}
4949

5050
SDL_PropertiesID props = SDL_GetWindowProperties(window);
@@ -54,7 +54,7 @@ int main(int, char**)
5454
if (!CreateDeviceD3D(hwnd))
5555
{
5656
CleanupDeviceD3D();
57-
return -1;
57+
return 1;
5858
}
5959

6060
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);

examples/example_sdl3_metal/main.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main(int, char**)
2424
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
2525
{
2626
printf("Error: SDL_Init(): %s\n", SDL_GetError());
27-
return -1;
27+
return 1;
2828
}
2929

3030
// Create SDL window graphics context
@@ -34,19 +34,19 @@ int main(int, char**)
3434
if (window == nullptr)
3535
{
3636
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
37-
return -1;
37+
return 1;
3838
}
3939
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
4040
SDL_ShowWindow(window);
4141

4242
// Create Metal device _before_ creating the view/layer
43-
id<MTLDevice> metalDevice = MTLCreateSystemDefaultDevice();
43+
id<MTLDevice> metalDevice = MTLCreateSystemDefaultDevice();
4444
if (!metalDevice)
4545
{
4646
printf("Error: failed to create Metal device.\n");
4747
SDL_DestroyWindow(window);
4848
SDL_Quit();
49-
return -1;
49+
return 1;
5050
}
5151
SDL_MetalView view = SDL_Metal_CreateView(window);
5252
CAMetalLayer* layer = (__bridge CAMetalLayer*)SDL_Metal_GetLayer(view);
@@ -128,7 +128,7 @@ int main(int, char**)
128128

129129
int width, height;
130130
SDL_GetWindowSizeInPixels(window, &width, &height);
131-
131+
132132
layer.drawableSize = CGSizeMake(width, height);
133133
id<CAMetalDrawable> drawable = [layer nextDrawable];
134134

examples/example_sdl3_opengl3/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int main(int, char**)
3030
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD))
3131
{
3232
printf("Error: SDL_Init(): %s\n", SDL_GetError());
33-
return -1;
33+
return 1;
3434
}
3535

3636
// Decide GL+GLSL versions
@@ -74,13 +74,13 @@ int main(int, char**)
7474
if (window == nullptr)
7575
{
7676
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
77-
return -1;
77+
return 1;
7878
}
7979
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
8080
if (gl_context == nullptr)
8181
{
8282
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
83-
return -1;
83+
return 1;
8484
}
8585

8686
SDL_GL_MakeCurrent(window, gl_context);

0 commit comments

Comments
 (0)