From 0cf9eb2f0fd8afd9b58060e3cb064fa5836f66f1 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 8 Nov 2014 21:01:49 +0100 Subject: Gracefully handle init failure on Windows. Conflicts: pugl/pugl_win.cpp --- pugl/pugl_win.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'pugl') 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; -- cgit v1.2.1