From 5ab5e54242c692605ac40098fbe8f0cda3566334 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 18 Mar 2015 13:24:59 +0100 Subject: [PATCH] (Windows) Improved window implementation It no longer leaks if it fails to create a threaded window Former-commit-id: 6df9bf1f62af8835d0824ab48fec0f4d80596da1 --- src/Nazara/Utility/Win32/WindowImpl.cpp | 9 ++++----- src/Nazara/Utility/Win32/WindowImpl.hpp | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index f3a25912a..0119ccb2a 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -27,7 +27,7 @@ #define GWL_USERDATA GWLP_USERDATA #endif -// N'est pas définit avec MinGW +// N'est pas défini avec MinGW #ifndef MAPVK_VK_TO_VSC #define MAPVK_VK_TO_VSC 0 #endif @@ -152,7 +152,7 @@ bool NzWindowImpl::Create(const NzVideoMode& mode, const NzString& title, nzUInt // On attend que la fenêtre soit créée mutex.Lock(); - m_thread = new NzThread(WindowThread, &m_handle, win32StyleEx, title.GetWideString().data(), win32Style, x, y, width, height, this, &mutex, &condition); + m_thread = NzThread(WindowThread, &m_handle, win32StyleEx, title.GetWideString().data(), win32Style, x, y, width, height, this, &mutex, &condition); condition.Wait(&mutex); mutex.Unlock(); #else @@ -221,13 +221,12 @@ void NzWindowImpl::Destroy() if (m_ownsWindow) { #if NAZARA_UTILITY_THREADED_WINDOW - if (m_thread) + if (m_thread.IsJoinable()) { m_threadActive = false; PostMessageW(m_handle, WM_NULL, 0, 0); // Pour réveiller le thread - m_thread->Join(); - delete m_thread; + m_thread.Join(); } #else if (m_handle) diff --git a/src/Nazara/Utility/Win32/WindowImpl.hpp b/src/Nazara/Utility/Win32/WindowImpl.hpp index 309cd20e7..472930b25 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.hpp +++ b/src/Nazara/Utility/Win32/WindowImpl.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -22,7 +23,6 @@ #if NAZARA_UTILITY_THREADED_WINDOW class NzConditionVariable; class NzMutex; -class NzThread; #endif class NzWindow; @@ -95,7 +95,7 @@ class NzWindowImpl : NzNonCopyable NzVector2i m_position; NzVector2ui m_size; #if NAZARA_UTILITY_THREADED_WINDOW - NzThread* m_thread; + NzThread m_thread; #endif NzWindow* m_parent; bool m_eventListener;