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); } } diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 186860066..48b8f1034 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -57,9 +57,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 a5e5f4712..b480bffd3 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -235,40 +235,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 b8a980ae5..99a4d1248 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -69,9 +69,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 f2940e279..aa1661bae 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -330,40 +330,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 { 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() 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()); } 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); } 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; } 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) 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 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