(Windows) Improved window implementation

It no longer leaks if it fails to create a threaded window


Former-commit-id: 6df9bf1f62af8835d0824ab48fec0f4d80596da1
This commit is contained in:
Lynix 2015-03-18 13:24:59 +01:00
parent fca8dc49e9
commit 5ab5e54242
2 changed files with 6 additions and 7 deletions

View File

@ -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)

View File

@ -11,6 +11,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Keyboard.hpp>
@ -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;