From b6b83936ac8083f7c66e890bf3f570b392da0be6 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 2 May 2008 11:05:49 +0000 Subject: [PATCH] Windows: Clean up window in case of exception thrown from WindowsDisplay.createWindow --- src/java/org/lwjgl/opengl/WindowsDisplay.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/java/org/lwjgl/opengl/WindowsDisplay.java b/src/java/org/lwjgl/opengl/WindowsDisplay.java index 9d2aa427..9e7e73e2 100644 --- a/src/java/org/lwjgl/opengl/WindowsDisplay.java +++ b/src/java/org/lwjgl/opengl/WindowsDisplay.java @@ -173,13 +173,18 @@ final class WindowsDisplay implements DisplayImplementation { nDestroyWindow(hwnd, hdc); throw new LWJGLException("Failed to get dc"); } - peer_info.initDC(getHwnd(), getHdc()); - int format = WindowsPeerInfo.choosePixelFormat(getHdc(), 0, 0, peer_info.getPixelFormat(), null, true, true, false, true); - WindowsPeerInfo.setPixelFormat(getHdc(), format); - showWindow(getHwnd(), SW_SHOWDEFAULT); - if (parent == null) { - setForegroundWindow(getHwnd()); - setFocus(getHwnd()); + try { + int format = WindowsPeerInfo.choosePixelFormat(getHdc(), 0, 0, peer_info.getPixelFormat(), null, true, true, false, true); + WindowsPeerInfo.setPixelFormat(getHdc(), format); + peer_info.initDC(getHwnd(), getHdc()); + showWindow(getHwnd(), SW_SHOWDEFAULT); + if (parent == null) { + setForegroundWindow(getHwnd()); + setFocus(getHwnd()); + } + } catch (LWJGLException e) { + nDestroyWindow(hwnd, hdc); + throw e; } } private native long nCreateWindow(DisplayMode mode, boolean fullscreen, int x, int y, boolean undecorated, boolean child_window, long parent_hwnd) throws LWJGLException;