aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2014-11-08 21:01:49 +0100
committerDavid Robillard <d@drobilla.net>2014-12-16 18:31:18 -0500
commit0cf9eb2f0fd8afd9b58060e3cb064fa5836f66f1 (patch)
tree52d81fc7ec751cde03d496d8cd9035efc6d37f09
parentc136194b24c013977e95d53c62d712e721d21661 (diff)
downloadpugl-0cf9eb2f0fd8afd9b58060e3cb064fa5836f66f1.tar.gz
pugl-0cf9eb2f0fd8afd9b58060e3cb064fa5836f66f1.tar.bz2
pugl-0cf9eb2f0fd8afd9b58060e3cb064fa5836f66f1.zip
Gracefully handle init failure on Windows.
Conflicts: pugl/pugl_win.cpp
-rw-r--r--pugl/pugl_win.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index 204afaf..5956fdd 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -116,8 +116,14 @@ puglCreateWindow(PuglView* view, const char* title)
impl->wc.hCursor = LoadCursor(NULL, IDC_ARROW);
impl->wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
impl->wc.lpszMenuName = NULL;
- impl->wc.lpszClassName = classNameBuf;
- RegisterClass(&impl->wc);
+ impl->wc.lpszClassName = strdup(classNameBuf);
+
+ if (!RegisterClass(&impl->wc)) {
+ free((void*)impl->wc.lpszClassName);
+ free(impl);
+ free(view);
+ return NULL;
+ }
int winFlags = WS_POPUPWINDOW | WS_CAPTION;
if (view->resizable) {
@@ -136,6 +142,7 @@ puglCreateWindow(PuglView* view, const char* title)
(HWND)view->parent, NULL, NULL, NULL);
if (!impl->hwnd) {
+ free((void*)impl->wc.lpszClassName);
free(impl);
free(view);
return 1;
@@ -163,6 +170,15 @@ puglCreateWindow(PuglView* view, const char* title)
SetPixelFormat(impl->hdc, format, &pfd);
impl->hglrc = wglCreateContext(impl->hdc);
+ if (!impl->hglrc) {
+ ReleaseDC(impl->hwnd, impl->hdc);
+ DestroyWindow(impl->hwnd);
+ UnregisterClass(impl->wc.lpszClassName, NULL);
+ free((void*)impl->wc.lpszClassName);
+ free(impl);
+ free(view);
+ return NULL;
+ }
wglMakeCurrent(impl->hdc, impl->hglrc);
return 0;