From cc01216e1c86281212f2df418dc198624c93484b Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 25 Jun 2014 15:23:31 +0200 Subject: [PATCH 1/9] Fixed crash in TaskScheduler Windows implementation Also replaced CreateEventA calls by CreateEventW calls to avoid one level of function call. Thanks to bacelar Former-commit-id: 4612e3fb0af8eef9ffd947d8edf55e4f2fa27c9b --- src/Nazara/Core/Win32/TaskSchedulerImpl.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp index c55d84202..09c3c1abd 100644 --- a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp +++ b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp @@ -34,11 +34,11 @@ bool NzTaskSchedulerImpl::Initialize(unsigned int workerCount) { Worker& worker = s_workers[i]; InitializeCriticalSection(&worker.queueMutex); - worker.wakeEvent = CreateEventA(nullptr, false, false, nullptr); + worker.wakeEvent = CreateEventW(nullptr, false, false, nullptr); worker.running = true; worker.workCount = 0; - s_doneEvents[i] = CreateEventA(nullptr, true, false, nullptr); + s_doneEvents[i] = CreateEventW(nullptr, true, false, nullptr); workerIDs[i] = i; s_workerThreads[i] = reinterpret_cast(_beginthreadex(nullptr, 0, &WorkerProc, &workerIDs[i], 0, nullptr)); @@ -149,7 +149,8 @@ NzFunctor* NzTaskSchedulerImpl::StealTask(unsigned int workerID) if (worker.workCount > 0) { - NzFunctor* task; + NzFunctor* task = nullptr; + if (TryEnterCriticalSection(&worker.queueMutex)) { if (!worker.queue.empty()) @@ -158,8 +159,6 @@ NzFunctor* NzTaskSchedulerImpl::StealTask(unsigned int workerID) worker.queue.pop(); worker.workCount = worker.queue.size(); } - else - task = nullptr; LeaveCriticalSection(&worker.queueMutex); } From 4d27f12fec9f06185dd6617abc349c882672abf9 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 25 Jun 2014 19:34:55 +0200 Subject: [PATCH 2/9] Fixed typo Former-commit-id: 746c6caea0f7f806db0e7554deb125030009e069 --- src/Nazara/Renderer/RenderWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index a59cbd457..367399c09 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -289,7 +289,7 @@ bool NzRenderWindow::OnWindowCreated() std::unique_ptr context(new NzContext); if (!context->Create(m_parameters)) { - NazaraError("Failed not create context"); + NazaraError("Failed to create context"); return false; } From c5b31d4f03a94ade7a6834e97703997229f4e7a5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 25 Jun 2014 19:35:53 +0200 Subject: [PATCH 3/9] Replaced CreateSemaphore call by CreateSemaphoreW Former-commit-id: 8f1897c846bc08d79a7298b1d95a2319c1aefffd --- src/Nazara/Core/Win32/SemaphoreImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Core/Win32/SemaphoreImpl.cpp b/src/Nazara/Core/Win32/SemaphoreImpl.cpp index b126c13ea..2561f4846 100644 --- a/src/Nazara/Core/Win32/SemaphoreImpl.cpp +++ b/src/Nazara/Core/Win32/SemaphoreImpl.cpp @@ -10,7 +10,7 @@ NzSemaphoreImpl::NzSemaphoreImpl(unsigned int count) { - m_semaphore = CreateSemaphore(nullptr, count, std::numeric_limits::max(), nullptr); + m_semaphore = CreateSemaphoreW(nullptr, count, std::numeric_limits::max(), nullptr); if (!m_semaphore) NazaraError("Failed to create semaphore: " + NzError::GetLastSystemError()); } From dcca3d03d44aad7647428cf99c603399cbfddbd7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jun 2014 21:09:31 +0200 Subject: [PATCH 4/9] Fixed warning on some compilers Former-commit-id: 588acff705e80008577f4b1f46580b70dc62615a --- include/Nazara/Audio/Algorithm.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Audio/Algorithm.inl b/include/Nazara/Audio/Algorithm.inl index b3f4d6700..9d8e4aa13 100644 --- a/include/Nazara/Audio/Algorithm.inl +++ b/include/Nazara/Audio/Algorithm.inl @@ -18,7 +18,7 @@ void NzMixToMono(T* input, T* output, unsigned int channelCount, unsigned int fr for (unsigned int j = 0; j < channelCount; ++j) acc += input[i*channelCount + j]; - output[i] = acc/channelCount; + output[i] = static_cast(acc/channelCount); } } From 032b2ed79b52770f6984d53762ac958ea11ed5b7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jun 2014 21:15:11 +0200 Subject: [PATCH 5/9] Removed explicit VectorI::operator[] Since Vector instances can be implicitely converted to T*, native operator[] will work on them Former-commit-id: 3f4a1822c514886dee7d9e5dab816c80e5c5ee99 --- include/Nazara/Math/Vector2.hpp | 3 --- include/Nazara/Math/Vector2.inl | 34 --------------------------------- include/Nazara/Math/Vector3.hpp | 3 --- include/Nazara/Math/Vector3.inl | 34 --------------------------------- include/Nazara/Math/Vector4.hpp | 3 --- include/Nazara/Math/Vector4.inl | 34 --------------------------------- 6 files changed, 111 deletions(-) diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index e0c060e21..373627cd8 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -55,9 +55,6 @@ class NzVector2 operator T*(); operator const T*() const; - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - const NzVector2& operator+() const; NzVector2 operator-() const; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 5da704243..bf19c4af7 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -226,40 +226,6 @@ NzVector2::operator const T*() const return &x; } -template -T& NzVector2::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 2) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 2)"; - - NazaraError(ss); - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector2::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 2) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 2)"; - - NazaraError(ss); - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - template const NzVector2& NzVector2::operator+() const { diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index fe2e33881..8a413c6af 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -67,9 +67,6 @@ template class NzVector3 operator T*(); operator const T*() const; - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - const NzVector3& operator+() const; NzVector3 operator-() const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index a90410a0d..0d0b08335 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -306,40 +306,6 @@ NzVector3::operator const T*() const return &x; } -template -T& NzVector3::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 3) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 3)"; - - NazaraError(ss); - throw std::out_of_range(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector3::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 3) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 3)"; - - NazaraError(ss); - throw std::out_of_range(ss.ToString()); - } - #endif - - return *(&x+i); -} - template const NzVector3& NzVector3::operator+() const { diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 90ad99664..7e30e71ee 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -50,9 +50,6 @@ template class NzVector4 operator T*(); operator const T*() const; - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - const NzVector4& operator+() const; NzVector4 operator-() const; diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 90a4da53a..77229fd5c 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -233,40 +233,6 @@ NzVector4::operator const T*() const return &x; } -template -T& NzVector4::operator[](unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i >= 4) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 4)"; - - NazaraError(ss); - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - -template -T NzVector4::operator[](unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i >= 4) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 4)"; - - NazaraError(ss); - throw std::domain_error(ss.ToString()); - } - #endif - - return *(&x+i); -} - template const NzVector4& NzVector4::operator+() const { From 76bfd0857ebcc7ee5196bde6d076205e022adc87 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jun 2014 21:16:36 +0200 Subject: [PATCH 6/9] Allowed asserts to throw exceptions instead of calling std::exit Former-commit-id: 892db922761a0a8122c60274b344c3e62de0a65f --- src/Nazara/Core/Error.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index 57e082160..e73a3e87a 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -44,13 +44,13 @@ void NzError::Error(nzErrorType type, const NzString& error, unsigned int line, s_lastErrorFunction = function; s_lastErrorLine = line; + if (type != nzErrorType_Warning && (s_flags & nzErrorFlag_ThrowException) != 0 && (s_flags & nzErrorFlag_ThrowExceptionDisabled) == 0) + throw std::runtime_error(error); + #if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE if (type == nzErrorType_AssertFailed) std::exit(EXIT_FAILURE); #endif - - if (type != nzErrorType_Warning && (s_flags & nzErrorFlag_ThrowException) != 0 && (s_flags & nzErrorFlag_ThrowExceptionDisabled) == 0) - throw std::runtime_error(error); } nzUInt32 NzError::GetFlags() From 126cd75e4db1fd8b6479d8c0d7e177fb07d500a6 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jun 2014 21:17:23 +0200 Subject: [PATCH 7/9] Fixed possible bug Former-commit-id: cc37ef2c51011d7a679a10d5386f9bbf0241d51f --- src/Nazara/Renderer/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 438e1df77..2f46170d4 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -795,7 +795,7 @@ bool NzRenderer::Initialize() { try { - NzErrorFlags errFlags(nzErrorFlag_ThrowException); + NzErrorFlags errFlags(nzErrorFlag_ThrowException, true); s_instanceBuffer.Reset(nullptr, NAZARA_RENDERER_INSTANCE_BUFFER_SIZE, nzBufferStorage_Hardware, nzBufferUsage_Dynamic); } catch (const std::exception& e) From 6e936b6120680427096c2deb24fb242fab978007 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jun 2014 21:18:22 +0200 Subject: [PATCH 8/9] Fixed Image::GetPixels returning wrong pointer when level is over 0 Former-commit-id: c54b77b3b7aee5ee9aeff9a022e94f33f4b45453 --- src/Nazara/Utility/Image.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index fd7108238..a6ceaf41a 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -11,6 +11,7 @@ #include ///TODO: Rajouter des warnings (Formats compressés avec les méthodes Copy/Update, tests taille dans Copy) +///TODO: Rendre les méthodes exception-safe namespace { @@ -768,7 +769,7 @@ nzUInt8* NzImage::GetPixels(unsigned int x, unsigned int y, unsigned int z, nzUI EnsureOwnership(); - return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height); + return GetPixelPtr(m_sharedImage->pixels[level], NzPixelFormat::GetBytesPerPixel(m_sharedImage->format), x, y, z, width, height); } unsigned int NzImage::GetSize() const From 53e5944b56105dbd0e35df763a2d76cd3ae5274f Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jun 2014 21:18:51 +0200 Subject: [PATCH 9/9] Fixed build error in debug mode Former-commit-id: 8992ced076980cf0101eb2c62923521e1c975763 --- src/Nazara/Utility/Win32/WindowImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index 43cf89fb2..64a1fae74 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -335,7 +335,7 @@ void NzWindowImpl::SetCursor(nzWindowCursor cursor) if (cursor > nzWindowCursor_Max) { NazaraError("Window cursor out of enum"); - return false; + return; } #endif