From fb68bf3a79bacbac8de8194a7649a41ac4fb12eb Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 24 Feb 2015 19:20:38 +0100 Subject: [PATCH] Fixed assertions handling An assertion will now either abort the program or throw an exception Former-commit-id: ee221e0934aeb7fbf625d0c891f828ce497ac720 --- src/Nazara/Core/Error.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index 42a297076..921fff968 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -17,7 +17,7 @@ void NzError::Error(nzErrorType type, const NzString& error) { - if ((s_flags & nzErrorFlag_Silent) == 0 || (s_flags & nzErrorFlag_SilentDisabled) != 0) + if (type == nzErrorType_AssertFailed || (s_flags & nzErrorFlag_Silent) == 0 || (s_flags & nzErrorFlag_SilentDisabled) != 0) NazaraLog->WriteError(type, error); s_lastError = error; @@ -27,16 +27,17 @@ void NzError::Error(nzErrorType type, const NzString& error) #if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE if (type == nzErrorType_AssertFailed) - std::exit(EXIT_FAILURE); + std::abort(); #endif - if (type != nzErrorType_Warning && (s_flags & nzErrorFlag_ThrowException) != 0 && (s_flags & nzErrorFlag_ThrowExceptionDisabled) == 0) + if (type == nzErrorType_AssertFailed || (type != nzErrorType_Warning && + (s_flags & nzErrorFlag_ThrowException) != 0 && (s_flags & nzErrorFlag_ThrowExceptionDisabled) == 0)) throw std::runtime_error(error); } void NzError::Error(nzErrorType type, const NzString& error, unsigned int line, const char* file, const char* function) { - if ((s_flags & nzErrorFlag_Silent) == 0 || (s_flags & nzErrorFlag_SilentDisabled) != 0) + if (type == nzErrorType_AssertFailed || (s_flags & nzErrorFlag_Silent) == 0 || (s_flags & nzErrorFlag_SilentDisabled) != 0) NazaraLog->WriteError(type, error, line, file, function); s_lastError = error; @@ -44,13 +45,14 @@ 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); + std::abort(); #endif + + if (type == nzErrorType_AssertFailed || (type != nzErrorType_Warning && + (s_flags & nzErrorFlag_ThrowException) != 0 && (s_flags & nzErrorFlag_ThrowExceptionDisabled) == 0)) + throw std::runtime_error(error); } nzUInt32 NzError::GetFlags()