diff options
author | Erik Faye-Lund <erik.faye-lund@collabora.com> | 2020-04-17 13:46:01 +0200 |
---|---|---|
committer | Erik Faye-Lund <erik.faye-lund@collabora.com> | 2020-04-20 11:48:33 +0200 |
commit | 9a88b8e153d7f0a9a31c00fc5f0542778cb15652 (patch) | |
tree | 07a11576d14219078acec88ee7a31e8fa64da938 | |
parent | 8044dac891af948f6cd1d9788463270eb9adc6f6 (diff) |
wglgears: omit paranoid error-checking
This code contains a lot of code that can't realistically fail; these
things can only fail on incorrect input, or under memory pressure. We're
passing correct input, and we're not yet at a point where memory
pressure is really possible.
So for the sake of readability, let's remove some overly paranoid
error-checking. It's not like these error-messages are all that useful
to most users, compared to running this in a debugger anyway.
This makes the code reasier to read, and makes it easier to add
meaningful error-checking where it actually matters in the future.
Reviewed-by: Brian Paul <brianp@vmware.com>
-rw-r--r-- | src/wgl/wglgears.c | 71 |
1 files changed, 26 insertions, 45 deletions
diff --git a/src/wgl/wglgears.c b/src/wgl/wglgears.c index 37423200..66cd9426 100644 --- a/src/wgl/wglgears.c +++ b/src/wgl/wglgears.c @@ -396,33 +396,29 @@ make_window(const char *name, int x, int y, int width, int height) wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = name; - if (!RegisterClass(&wc)) { - printf("failed to register class\n"); - exit(0); - } + RegisterClass(&wc); dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; AdjustWindowRectEx(&winrect, dwStyle, FALSE, dwExStyle); - if (!(hWnd = CreateWindowEx(dwExStyle, name, name, - WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, - x, y, - winrect.right - winrect.left, - winrect.bottom - winrect.top, - NULL, NULL, hInst, NULL))) { - printf("failed to create window\n"); + hWnd = CreateWindowEx(dwExStyle, name, name, + WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, + x, y, + winrect.right - winrect.left, + winrect.bottom - winrect.top, + NULL, NULL, hInst, NULL); + + hDC = GetDC(hWnd); + pixelFormat = ChoosePixelFormat(hDC, &pfd); + if (!pixelFormat) { + printf("ChoosePixelFormat failed\n"); exit(0); } - if (!(hDC = GetDC(hWnd)) || - !(pixelFormat = ChoosePixelFormat(hDC, &pfd)) || - !(SetPixelFormat(hDC, pixelFormat, &pfd)) || - !(hRC = wglCreateContext(hDC)) || - !(wglMakeCurrent(hDC, hRC))) { - printf("failed to initialise opengl\n"); - exit(0); - } + SetPixelFormat(hDC, pixelFormat, &pfd); + hRC = wglCreateContext(hDC); + wglMakeCurrent(hDC, hRC); if (use_srgb || samples > 0) { /* We can't query/use extension functions until after we've @@ -479,32 +475,17 @@ make_window(const char *name, int x, int y, int width, int height) wglDeleteContext(hRC); DeleteDC(hDC); - if (!(hWnd = CreateWindowEx(dwExStyle, name, name, - WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, - 0, 0, - winrect.right - winrect.left, - winrect.bottom - winrect.top, - NULL, NULL, hInst, NULL))) { - printf("failed to create window\n"); - exit(0); - } - - if (!(hDC = GetDC(hWnd))) { - printf("GetDC() failed.\n"); - exit(0); - } - if (!SetPixelFormat(hDC, pixelFormat, &pfd)) { - printf("SetPixelFormat failed %d\n", (int) GetLastError()); - exit(0); - } - if (!(hRC = wglCreateContext(hDC))) { - printf("wglCreateContext() failed\n"); - exit(0); - } - if (!wglMakeCurrent(hDC, hRC)) { - printf("wglMakeCurrent() failed\n"); - exit(0); - } + hWnd = CreateWindowEx(dwExStyle, name, name, + WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, + 0, 0, + winrect.right - winrect.left, + winrect.bottom - winrect.top, + NULL, NULL, hInst, NULL); + + hDC = GetDC(hWnd); + SetPixelFormat(hDC, pixelFormat, &pfd); + hRC = wglCreateContext(hDC); + wglMakeCurrent(hDC, hRC); } ShowWindow(hWnd, SW_SHOW); |