The throwing of exceptions can now be disabled, and in this case a handler function is called instead.
This commit is contained in:
parent
25a4ff1c8e
commit
4f7a6256a9
@ -94,6 +94,7 @@ SET(CORE_INC_FILES
|
||||
)
|
||||
|
||||
SET(IMPL_SRC_FILES
|
||||
source/Impl/ErrorHandling.cpp
|
||||
source/Impl/MarchingCubesTables.cpp
|
||||
source/Impl/RandomUnitVectors.cpp
|
||||
source/Impl/RandomVectors.cpp
|
||||
|
@ -26,8 +26,10 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include <cstdlib> //For std::exit
|
||||
#include <iostream> //For std::cerr
|
||||
#include <stdexcept>
|
||||
|
||||
#define POLYVOX_ASSERTS_ENABLED
|
||||
//#define POLYVOX_THROW_ENABLED
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define POLYVOX_HALT() __debugbreak()
|
||||
@ -54,7 +56,7 @@ freely, subject to the following restrictions:
|
||||
{ \
|
||||
std::cerr << std::endl << std::endl; \
|
||||
std::cerr << " PolyVox Assertion Failed!" << std::endl; \
|
||||
std::cerr << " -------------------------" << std::endl; \
|
||||
std::cerr << " =========================" << std::endl; \
|
||||
std::cerr << " Condition: " << #condition << std::endl; \
|
||||
std::cerr << " Message: " << (message) << std::endl; \
|
||||
std::cerr << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \
|
||||
@ -98,4 +100,25 @@ freely, subject to the following restrictions:
|
||||
#define POLYVOX_STATIC_ASSERT(condition, message) StaticAssert<(condition)>::ERROR_The_static_assertion_has_failed();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exceptions
|
||||
* ----------
|
||||
* ...
|
||||
*/
|
||||
#ifdef POLYVOX_THROW_ENABLED
|
||||
#define POLYVOX_THROW(type, message) throw type((message))
|
||||
#else
|
||||
namespace PolyVox
|
||||
{
|
||||
typedef void (*ThrowHandler)(std::exception& e, const char* file, int line);
|
||||
|
||||
ThrowHandler getThrowHandler();
|
||||
void setThrowHandler(ThrowHandler newHandler);
|
||||
}
|
||||
|
||||
#define POLYVOX_THROW(type, message) \
|
||||
type except = (type)((message)); \
|
||||
getThrowHandler()((except), __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#endif //__PolyVox_ErrorHandling_H__
|
||||
|
@ -21,11 +21,9 @@ freely, subject to the following restrictions:
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "PolyVoxCore/Impl/ErrorHandling.h"
|
||||
#include "PolyVoxCore/Impl/Utility.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
//Note: this function only works for inputs which are a power of two and not zero
|
||||
@ -33,17 +31,17 @@ namespace PolyVox
|
||||
uint8_t logBase2(uint32_t uInput)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(uInput != 0);
|
||||
assert(isPowerOf2(uInput));
|
||||
POLYVOX_ASSERT(uInput != 0, "Cannot compute the log of zero.");
|
||||
POLYVOX_ASSERT(isPowerOf2(uInput), "Input must be a power of two in order to compute the log.");
|
||||
|
||||
//Release mode validation
|
||||
if(uInput == 0)
|
||||
{
|
||||
throw std::invalid_argument("Cannot compute the log of zero.");
|
||||
POLYVOX_THROW(std::invalid_argument, "Cannot compute the log of zero.");
|
||||
}
|
||||
if(!isPowerOf2(uInput))
|
||||
{
|
||||
throw std::invalid_argument("Input must be a power of two in order to compute the log.");
|
||||
POLYVOX_THROW(std::invalid_argument, "Input must be a power of two in order to compute the log.");
|
||||
}
|
||||
|
||||
uint32_t uResult = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user